指针中(星号)的确切用途是什么?

新手上路,请多包涵

我是编程新手,我正试图围绕“指针”的想法。


 int main()
{
    int x = 5;
    int *pointerToInteger = & x;
    cout<<pointerToInteger;

}

为什么当我 cout << pointerToInteger; 输出是十六进制值,但是当我使用 cout << *pointerToInteger; 输出是5(x=5)。

原文由 iansmathew 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 348
1 个回答

* 根据上下文有不同的含义。

  1. 指针的声明
   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.

  1. 取消引用表达式中的指针。
    int i = 0;
   int* ap = &i;   // ap points to i
   *ap = 10;       // Indirectly sets the value of i to 10

  1. 乘法运算符。
    int i = 10*20; // Needs no explanation.

原文由 R Sahu 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
logo
Stack Overflow 翻译
子站问答
访问
宣传栏