我是编程新手,我正在努力思考“指针”的概念。
int main()
{
int x = 5;
int *pointerToInteger = & x;
cout<<pointerToInteger;
}
为什么当我cout << pointerToInteger;
输出是一个十六进制值,但是当我使用 cout << *pointerToInteger;
时输出为 5 ( x=5)。
最佳答案
*
根据上下文有不同的含义。
指针声明
int* ap; // It defines ap to be a pointer to an int. void foo(int* p); // Declares function foo. // foo expects a pointer to an int as an argument.
取消引用表达式中的指针。
int i = 0; int* ap = &i; // ap points to i *ap = 10; // Indirectly sets the value of i to 10
乘法运算符。
int i = 10*20; // Needs no explanation.
关于c++ - 指针中(星号)的确切用途是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36962658/