gpt4 book ai didi

c++ - 在指针声明中放置星号

转载 作者:IT老高 更新时间:2023-10-28 12:00:25 34 4
gpt4 key购买 nike

我最近决定我必须最终学习 C/C++,关于指针,或者更准确地说,我不太了解它们的定义。

这些例子怎么样:

  1. int* 测试;
  2. int *test;
  3. int * test;
  4. int* test,test2;
  5. int *test,test2;
  6. int * test,test2;

现在,据我了解,前三种情况都在做同样的事情:Test 不是一个 int,而是一个指向 int 的指针。

第二组示例有点棘手。在案例 4 中,test 和 test2 都是指向 int 的指针,而在案例 5 中,只有 test 是指针,而 test2 是“真正的”int。案例6呢?同案例5?

最佳答案

4、5、6是同一个东西,只是test是一个指针。如果你想要两个指针,你应该使用:

int *test, *test2;

或者,甚至更好(让一切都清楚):

int* test;
int* test2;

关于c++ - 在指针声明中放置星号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/180401/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com