I put the code directly.
#include <stdio.h>
struct A
{
int a;
int b;
};
int main()
{
struct A test;
double *p = (double *)&(test.a);
*p = 5;
printf("variable a: %d\n", &test.a);
printf("variable b: %d\n", &test.b);
return 0;
}
I run this code in centos7, the compiler is gcc4.8.5.And my computer uses little ending to store.
As you see, the memory of variable b will be overwritten, I expected a is 0x0000 0005 and b is 0x0000 0000.
But the answer is:
variable a: 0
variable b: 1075052544
Why variable a is 0x 0000 0000 and b is 0x4014 0000?