as far as I knew when a program is loaded into memory uses 4 segments: text, data, stack, and heap. The global variables are recorded in the data segment while the local variables in the stack. In addition, by theory it is known that the addresses of the data segment must be lower than those of the stack; but I do not see that when executing this little program
#include <stdio.h>
static int a = 10;
void main( void ) {
int b = 5;
printf( "%p %p", &a, &b );
}
What I see as output is the global variable being stored in 0x100402010
while b in 0xffffcc0c
. But obviously 0x100402010
is greater than 0xffffcc0c
, which seems to contradict, according to the theory, the way in which the memory assigned to a program is organized. Why is the address of b (which is on the stack) smaller? Or does not% p not allow me to see the full memory address and only let me see the last 4 bytes? EYE: I'm using C, gcc, and Win-64 bits.