C Program 5
C Program 5
• The variables that are used to store the data are called members of the
structure.
• Structure definition is terminated with a semicolon.
• We can create the structure for a person as shown below:
DECLARATION OF STRUCTURE VARIABLES
• Here the above statement declares that the variables s1 and s2 are variables
of type STUDENT(which is of type as struct student).
Accessing Members of a Structure
Example:
struct student s1={“CANARA”,”4CB”,18,25.0};
• Reading and writing structure variable:
Based on the member type structure members can use input and output
statements for reading writing.
printf(“\n the student details are”);
printf(“\n Name: %s”,s.name);
printf(“\nUSN: %s”,s.usn);
printf(“\n age:%d”,s.age);
printf(“\n marks: %f”, s.marks);
}
STRUCTURES WITHIN STRUCTURES (NESTED STRUCTURES):
A structure within a structure is called nested structure i.e. a structure is a
member of another structure.
We can create nested structures in two ways
1. Placing complete definition of a structure inside the definition of another
structure.
2. Structure is defined separately and a variable of structure can be placed
inside the definition of another structure definition.
• ACCESSING NESTED STRUCTURE MEMBERS:
– SYNTAX:
– EXAMPLE:
S.dob.day=20;
S.dob.month=3;
S.dob.year=2018;
• Array of structures:
An array of structure is declared in the same way as we had declared
array of built in data type.
Syntax:
POINTERS