Char pointer cout = garbage

Can someone explain why this return the char 'a' followed by a bunch of gibberish? For all other data types it responds with the memory address of test.

1
2
3
4
char test = 'a';
char *testPtr = &test;

cout << testPtr << endl;

That's because in the case of char* it will interpret the address as the start of a C string.
http://en.wikipedia.org/wiki/C_string
It will keep printing until it reaches a null character, so a lot of what it prints will be garbage.
Thanks!
Topic archived. No new replies allowed.