c – 指针中(星号)的用途究竟是什么?
作者:互联网
我是编程的新手,我正试图围绕“指针”的想法.
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.
标签:dereference,c,pointers,memory-address 来源: https://codeday.me/bug/20190928/1828563.html