Documente Academic
Documente Profesional
Documente Cultură
For understanding more, run the below program and check for memory mapping of
the structure variable.
#include "stdio.h"
void main()
{
struct st_demo
{
char ch;
int i;
};
struct st_demo s;
printf(" Size of int = %d \n\n Size of char = %d \n\n Size of struct = %d
",sizeof(s.i), sizeof(s.ch),sizeof(s));
getch();
}
Explanation of the above program:
Let assume the size of char is 1 byte and int is 4 bytes(Variable sizes depends on
Platforms/Compilers).
According to this, the size of structure variable s should be 5(1+4) bytes.
If anything needs to be added for the above article, Please post it in comment
section.