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?
cout << reinterpret_cast<void*>(c) << endl;
or just
cout << (void*)c << endl;
Try casting it as a const void*
:
cout << static_cast<const void*>(c) << endl;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With