c++ - 指向指针的指针有什么意义?

标签 c++ pointers

这样做有什么区别:

int i = 5, j = 6, k = 7;
int *ip1 = &i, *ip2 = &j;



int *ipp = ip1;

然后这样做:

int **ipp2 = &ip1;

他们做的不是一样的吗?持有一个指向变量的指针(ip1),我?

最佳答案

ipp2 指向 ip1。这与指向 i 完全不同。

示例代码:

int *ip1 = &i;
int **ipp2 = &ip1;
printf("%d\n", **ipp2);    // 5
ip1 = &j;
printf("%d\n", **ipp2);    // 6

关于c++ - 指向指针的指针有什么意义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23178694/

相关文章:

c++ - 使用 std::unique_ptr 将所有权转移到函数

c - 有没有更好的方法来管理C中的文件指针?

delphi - 在 TreeView 节点内存储接口(interface)指针

c - C 中的链表,最后一个节点指向 NULL?

C++ 头文件和命名空间

c++ - 如何将一个 exe 项目链接到另一个 exe 项目中的类

c++ - sdl_image 找不到我的jpg图片;不会加载

c++ - Union 在内存中的存储

c++ - 在指针中存储无符号整数

c - 错误 : request for member 'Name' in something not a structure or union