|
4. Size of Structures
|
|
The size of a structure in C can be greater than the sum of the sizes of its members. |
To calculate the sizes of user-defined types, the compiler takes into account any alignment space needed for complex user-defined data structures. |
struct student{
char grade; /* char is 1 byte long */
/* padding */
int age; /* int is 4 bytes long */
};
printf("%zu", sizeof(struct student)); // 8
|
|
|
|
|
|
|