code:
#include <stdio.h>
int main() {
int a;
printf("%p\n", &a);
char b[10];
printf("%p\n", &b);
int c;
printf("%p\n", &c);
}
outputs:
0061fefc
0061fef2
0061feec
It is obvious that b occupies 12 bytes memory becuase the default memory alignment makes the start address of c is a multiple of 4. It is possible to disable the memory alignment? I know #pragma pack can pack a structure, can it pack a local variable to make b occupy only 10 bytes? This is an interview question that makes me interested. Any help will be appreciated!