I would like to get the address of an string-constant in C.
char * const MYCONST = "StringString";
As far as I know consts are "saved" in the Text/Code Segment of the memory. When I try to get the address of the first element in MYCONSt:
printf("%p\n",&(MYCONST));
As result I get 0x7fff15342e28, which is in the stack and not in the Text/Code segement. Can anybody please help me get the address of a string-constant in C?
//edit I can't find the correct answer so far: When I write
char * const MYCONST1 = "StringString";
printf("Address of MYCONST1: %p\n",MYCONST1);
char * const MYCONST2 = "StringString";
printf("Address of MYCONST2: %p\n",(void*)MYCONST2);
this is the output:
Address of MYCONST1: 0x400b91
Address of MYCONST2: 0x400b91
But they should have different addresses, because the are different constants. Can anybody explain me while the result has a length of seven and not 0x7fffa5dd398c like a locale variable.
Thanks!