I have a basic question about char*
I don't understand
char* aString = "Hello Stackoverflow";
The Pointer points at the first character of the character chain.
cout << *aString; // H
but why is the whole string saved in the pointer?
cout << aString //Hello Stackoverflow
I would expect an address, aren't addresses saved in pointers? Where is the address of "Hello Stackoverflow"?
Any help much appreciated
There is an overload for operator<<(ostream&, char const*)
which output the null-terminated string starting at that pointer and which is preferred to the operator ostream::operator<<(void*)
which would have output the address.
If you want the address, cast the pointer to void*
.
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