Structure Definition
When
a structure is declared, there is no memory allocated for storing any data. The
memory is set aside to any structure only when it is defined. The structure
definition creates structure variables and allocates storage space for them.
The individual members of the structure variables are stored in contiguous
memory locations. To define a structure variable we use the structure header
followed by variable(s) name and semicolon. Consider we have declared a
structure student then the statement:
struct
student s1,s2;
creates
two variables s1 and s2 of type student and allocates memory to its members as shown in fig:
From fig. it is clear that each structure variable gets
separate memory for storing values for
its memebers. The memory reserved for structure variable s1 is quql to the sum of bytes the individual memebers of the
structure acquire i.e. total 26 bytes.
The structure variables can also be created during the
declaration of the structure. For example :
struct
student
{
int rollno;
char name [20];
float marks;
} s1,s2;
Post a Comment