我学习C++,我发现这对一本书:指针和引用操作符(&)
#include <iostream>
using namespace std;
int main()
{
int Age = 30;
int* pInteger = &Age; // pointer to an int, initialized to &Age
// Displaying the value of pointer
cout << “Integer Age is at: 0x” << hex << pInteger << endl;
return 0;
}
书中说,输出是其中年龄存储在内存中的地址。
但是,这本书不谈论这个:
*pInteger = &Age;
pInteger = &Age;
是什么这两个任务之间的区别?
'&'符号与类型一起使用时,声明一个引用。与变量一起使用时,返回变量的地址或位置。例如:'int&' - 声明一个引用; “&Age” - “Age”的返回位置。 –