On Sep 22, 2006, at 7:42 PM, Byron Clark wrote:

Your understanding of pointers and how they work is just fine.  What's
missing is how cout (specifically ostream::operator<<) is handling them.
 In most cases 'cout << pointer' will print the pointer address.  The
exception is when pointer is a 'char *' or 'wchar_t *' in any of its
forms.  In those cases, ostream::operator<< is overloaded to place the
NULL terminated string on the output stream instead of the address
pointed to by the pointer.


Yes, and this is to deal with C 'strings', which were not deemed worthy of their own datatype. They are more of a library coding convention with some limited compiler support, and thus libraries that deal with the C world of the Single Big Array must make a special case out of char pointers and arrays.

Backward compatibility with C is probably the biggest source of nasty surprises in C++, which encourages you to think at a higher level, and provides nice tools for it, but must ultimately also reduce to viewing the world as a Single Big Array.

                --Levi

/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/

Reply via email to