cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
Char pointer cout = garbage
Char pointer cout = garbage
Jul 14, 2011 at 10:52pm UTC
Toxn
(4)
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;
Jul 14, 2011 at 11:01pm UTC
Athar
(4466)
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
Jul 15, 2011 at 12:13am UTC
LB
(13399)
It will keep printing until it reaches a null character, so a lot of what it prints will be garbage.
Jul 22, 2011 at 11:56pm UTC
Toxn
(4)
Thanks!
Topic archived. No new replies allowed.