Question

int *i = new int;
cout << &i << endl << i;
delete i;
i = 0;

i get this output:

0031FB2B

0057C200

Why 2 different addresses? Isn't & referencing the address of the dynamic pointer and i itself the address of the pointer, which should be the same address?

Was it helpful?

Solution

&i is the address of the pointer. This is the place where the value returned by new will be stored. i is the value of the pointer itself, this is the value returned by new.

And just for completeness, *i is the value of the integer pointed to, which at the moment is uninitialized, but this is where your actual data will go.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top