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)
|