指针需要指针 [英] Need of Pointer to pointer
本文介绍了指针需要指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是必要的,用于存储指针的地址?
What is necessary for storing the address of a pointer?
int a = 2;
int *p = &a;
int **q = &p;
什么实际用途?实时应用。
Any practical use? Real time applications.
推荐答案
A **
只是一个指针的指针。那么,一个 * P
包含一个 P
, P的地址**
包含一个 p *
包含一个 p
对象的地址的地址。
A **
is just a pointer to a pointer. So where an *p
contains the address of an p
, p**
contains the address of an p*
that contains the address of an p
object.
**
当你想preserve甚至外的函数调用的内存分配或分配使用。
**
is used when you want to preserve the Memory-Allocation or Assignment even outside of a function call.
另外,请查阅此文章。
示例: -
void allocate(int** p)
{
*p = (int*)malloc(sizeof(int));
}
int main()
{
int* p = NULL;
allocate(&p);
*p = 1;
free(p);
}
这篇关于指针需要指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文