I print addresses and strings from the following two declarations and initializations:
char * strPtr = (char *) "This is a string, made on the fly."; char charArray [] = "Chars in a char array variable.";
When printing, the following output is output with completely different addresses for the variables charArray and strPtr. Question: "Why?"
Print
printf( "%10s%40s%20p\n", "strPtr", strPtr, &(*strPtr)); printf( "%10s%40s%20p\n", "charArray", charArray, charArray);
Output:
strPtr This is a string, made on the fly. 0x400880 charArray Chars in a char array variable. 0x7fff12d5ed30
Different addresses, as you can see: 0x400880 vs 0x7fff12d5ed30
The rest of the variable declared before this has addresses such as charArray.
Again, the question arises: "Why are the addresses different?" Thanks for any help.
mlw
source share