Tutorial Question to Pointer2Pointer

1
2
3
4
5
6
char1 = 's';
char_Pointer = &char1;
char ** Ptr2Ptr = &char_Pointer;

cout << "char1= " << char1 << ", and it's address (Pointer1)= " << char_Pointer;
cout << "Pointer 2 Pointer1: " << Ptr2Ptr << " Ptr2Ptr: (*) = " << *Ptr2Ptr << ", 2nd reference level (**): " << **Ptr2Ptr;


char1 = s and it's address (Pointer1)= s <--?
Pointer 2 Pointer1: 0x44b024 Ptr2Ptr: (*) = s  <--? , 2nd reference level (**): s


And the strange things for me are the two 's' (marked with <--?), where I expected two addresses... ?!? Can Anyone explain to me why? (for sure :-)
Thanks!
<< treats char pointers like c strings, and therefore it prints the string they point to, rather than the address.

if you want to print the address, you'll need to cast it to a different pointer type, like a void*:

1
2
cout << char_Pointer; // prints a string
cout << static_cast<void*>(char_Pointer);  // prints the address 


Thanks!
Topic archived. No new replies allowed.