Structures and Memory
Explore how structures are stored in memory with the help of an interactive example.
We'll cover the following...
How are structures stored in memory?
Structure members are stored in consecutive memory locations. The size of the structure variable is at least equal to the sum of sizes of structure elements.
Example program
See the code given below!
Press + to interact
# include <stdio.h>int main( ){// Declares structure employeestruct employee{// Members of structurechar name ;int age ;float salary ;} ;// Initalizes structure variable e1struct employee e1 = { 'A', 23, 4000.50 } ;// Address of structure membersprintf ("%u %u %u\n", &e1.name, &e1.age, &e1.salary);// Size of structure membersprintf ("%d %d %d\n", sizeof(e1.name), sizeof(e1.age), sizeof(e1.salary));// Size of structure variableprintf ("%d\n", sizeof(e1));return 0;}
Explanation
From the above code, you can see that ...