can anybody tell me why the size of the class is 16
-
i have a class as mentioned below.The size of the class is only 16.Can anybody give me an explanation for this.Is this because of padding class EXP { char c1; char c2; int i1; int i2; char *ptr; static int mem; }; THANKS IN ADVANCE
-
i have a class as mentioned below.The size of the class is only 16.Can anybody give me an explanation for this.Is this because of padding class EXP { char c1; char c2; int i1; int i2; char *ptr; static int mem; }; THANKS IN ADVANCE
There are "
paddings
" between some members of a structure. This is for convenience for the CPU to access. But you can change the padding size. To view the positions and the sizes of paddings, you can list the addresses of each members as below.EXP obj;
printf("obj.c1: 0x%p \nobj.c2: 0x%p \nobj.i1: 0x%p \n", &obj.c1, &obj.c2, &obj.i1);
Maxwell Chen
-
i have a class as mentioned below.The size of the class is only 16.Can anybody give me an explanation for this.Is this because of padding class EXP { char c1; char c2; int i1; int i2; char *ptr; static int mem; }; THANKS IN ADVANCE