That's because you output the addresses of the pointers, not the addresses of the string literals. Try this.
Oh, and for the fun of it, try this too.Code:const char* myStringconst()
{
return "Foob";
}
int main()
{
const void *sconst1 = myStringconst();
const void *sconst2 = myStringconst();;
cout << '\n' << sconst1
<< '\n' << sconst2;
const void *sconst3 = myStringconst();;
const void *sconst4 = myStringconst();;
cout << '\n' << sconst3
<< '\n' << sconst4
<< '\n';
return 0;
}
Outcome may depend on your compiler options.Code:int main()
{
const void *p1 = "foo", p2 = "foo", p3 = "foo";
std::cout << p1 << '\n' << p2 << '\n' << p3 << std::endl;
}