char* - why is there no address in the pointer?
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*
.
The string is saved sequentially, starting from that position. The rules of C, inherited by C++ simply state that when you try to use a char *
as a string, it will keep reading characters until encountering a 0 byte.
If you do want to get an address, tell cout
to not interpret it as a "string":
std::cout << (void *)aString << std::endl;
EDIT
Where does the standard state that 0 == '\0'?
From a C++11 draft, section 2.3-3:
The basic execution character set and the basic execution wide-character set shall each contain all the members of the basic source character set, plus control characters representing alert, backspace, and carriage return, plus a null character (respectively, null wide character), whose representation has all zero bits.