TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: NEIL HELLER
from: CAMERON CLARK
date: 1997-08-10 02:53:00
subject: Re: Printing pointer values

NH> Given the following code:
NH> 
NH> char aStr[10] = "abcdefgh";
NH> char * aPtr = &aStr[5];
NH> 
NH> cout << aPtr << endl;
NH> 
NH> The output is garbage.  How does one correct print the value of a
NH> pointer?
    aPtr is a typed pointer, in this case is a "char*". You must type
    cast the pointer so the compiler no longer thinks aPtr is a string.
    cout << (typecast)aPtr << endl;
    Replace typcast with something like int* and see what it does.
--- GEcho 1.00
---------------
* Origin: Digital OnLine Magazine! - (409)838-8237 (1:3811/350)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.