C++ pointer address issue

后端 未结 1 824
死守一世寂寞
死守一世寂寞 2021-01-29 16:27
int *i = new int;
cout << &i << endl << i;
delete i;
i = 0;

i get this output:

0031FB2B

0057C200

Why 2 di

相关标签:
1条回答
  • 2021-01-29 17:04

    &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.

    0 讨论(0)
提交回复
热议问题