我是C++的新手,我有一段这样的代码:
int firstvalue=10;
int * mypointer;
mypointer = &firstvalue;
cout << "pointer is " << *mypointer << '\n';
cout << "pointer is " << mypointer << '\n';
cout << "pointer is " << &mypointer << '\n';
Run Code Online (Sandbox Code Playgroud)
结果是:
pointer is 10
pointer is 0x7ffff8073cb4
pointer is 0x7ffff8073cb8
Run Code Online (Sandbox Code Playgroud)
任何人都可以向我解释为什么"mypointer"和"&mypointer"的结果不同?
非常感谢.
mypointer是变量的值mypointer.由于你的任务,这个价值是地址firstvalue.&mypointer是变量的地址mypointer.也就是地址mypointer.那么,mypointer是地址firstvalue,&mypointer是地址mypointer.由于firstvalue和mypointer是不同的变量,它们具有不同的地址.
| 归档时间: |
|
| 查看次数: |
89 次 |
| 最近记录: |