If you want to print the address, you must cast char* to void* , as
const char *str = "how are you\n"; cout << (void*) str << endl;
In the absence of translation, cout sees str as const char* (which is actually the case), and therefore cout thinks that you intend to print a string with a null char!
Think about it: if you want coud << str print the address, how would you print the string yourself?
-
In any case, this is a more detailed explanation:
operator<< overloaded for char* as well as void* :
If there is no translation, the first overload is called first, but when you click on void* , the second overload is called!
source share