Why does streaming a char pointer to cout not print an address?

Overload resolution selects the ostream& operator<<(ostream& o, const char *c); which is used for printing C-style strings. You want the other ostream& operator<<(ostream& o, const void *p); to be selected. You are probably best off with a cast here:

 cout << static_cast<void *>(cptr) << endl;

Leave a Comment