I have a simple C program of below type
#include<stdio.h>
struct test{
char a;
char b;
char c;
char d;
int e;
};
void main() {
struct test mem = {0xa, 0xb, 0xc, 0xd, 0xef12};
long int *tmp = (long int *)(&mem.a);
printf("Struct in binary %p : 0x%lx\n", &mem.a, *tmp);
printf("Printing only a member %p : 0x%x\n", &(mem.e), *(int *)(&(mem.e)));
}
The output of above program is as below on a Big endian machine :
Struct in binary 0x7ffc1206abc0 : 0xef120d0c0b0a
Printing only a member 0x7ffc1206abc4 : 0xef12
The question is that why is the raw output of the struct in the reverse order of its members' values?
The address of 'member e' is still 4 bytes from the start of the struct base address..!