Your compiler has done something called string concatenation. You indicated that you need two pointers, both pointing to the same string literal, so it made only one copy of the literal.
Technically: he should have complained about you for not specifying "const" pointers
const char* p = "abc";
Perhaps this is due to the fact that you are using Visual Studio or using GCC without -Wall.
If you want them to be stored twice in memory, try:
char s1[] = "abc"; char s2[] = "abc";
Here you explicitly state that you need two arrays of c-string characters, not two pointers to characters.
Caveat: String pooling is a compiler / optimizer function, not a language facet. Since such different compilers in different environments will create different behavior depending on factors such as optimization level, compiler flags and string values ββin different compilation units.
kfsone Sep 30 '13 at 7:01 2013-09-30 07:01
source share