Can someone explain to me why *x is consistently returning 0 while *(x + 1) returns values like -805306368, 536870912?
int * x = malloc(sizeof(int) * 2);
printf("%d, %d\n", *x, *(x + 1));
I'm using gcc, but have experienced the same behavior with clang.
My understanding was that malloc would allocate enough memory on the heap for two int values. I'm assuming that *x will reference the first uninitialized int while *(x + 1) will reference the second uninitialized int.
I don't think this is a duplicate of this because *x is always 0. I have a decent grasp of why *(x + 1) is returning "garbage", but less so for why *x is so consistently 0.