What you are trying to do could be achieved by:
int number = 10;
int* pointerOne = &number;
int** pointerTwo = &pointerOne;
cout << pointerTwo;
Pointers hold addresses. When you do pointerTwo = pointerOne;
you are copying to pointerTwo
the value pointerOne
points. The address of a int*
has type int**
. You never touched pointerOne's
address. You never used the &
to extract it.
If you use pointerOne
you will access the address. To access the place it points to you have to dereference: *pointerone
.
So, when you dereference: *pointerTwo
it should be equal to pointerOne
, NOT to &pointerOne
.
Check what the following commands prints:
cout << (*pointerTwo == pointerOne);
cout << '\n' << (pointerTwo == &pointerOne);