Reputation: 463
int *i = new int(1);
cout << i << endl;
Will print the address of the integer.
char *c="cstring";
cout << c << endl;
cout << &(*c) << endl;
Will both print "cstring". I guess this behavior can simply be explained with the implementation of ostream& operator<< (ostream& out, const char* s );
in the IOstream Library.
But what to do if you actually want to print the address of the data c refers to?
Upvotes: 4
Views: 4328
Reputation: 10477
Try casting it as a const void*
:
cout << static_cast<const void*>(c) << endl;
Upvotes: 1
Reputation: 5856
cout << reinterpret_cast<void*>(c) << endl;
or just
cout << (void*)c << endl;
Upvotes: 8