printf("address of literal: %p \n", "abc");
char alpha[] = "abcdef";
printf("address of alpha: %p \n", alpha);
Above, literal
is stored in static memory, alpha
is stored in dynamic memory. I read in a book that some compilers show these two addresses using different number of bits (I only tried using gcc on Linux, and it does show different number of bits). Does it depend on the compiler, or the operating system and hardware?
alpha
is stored e.g. in the stack or another dynamic memory segment. Theliteral
is stored inside the code segment. These are different address ranges.The addresses are platform dependant. In most cases the pointer size is 4 bytes long, but the addresses for the different segments are in different ranges.
The addresses are platform dependant.
The linker is responsible for the address assignment. You may want to enable an option to let the linker produce an address map file.
The dynamic parts are also called data segments. The static parts are code segments. You will find a lot literature searching for this term for your platform (e.g. search for "x86 memory segmentation").