3 回答

TA貢獻(xiàn)1808條經(jīng)驗(yàn) 獲得超4個贊
A **只是指向指針的指針。因此,其中*p包含的地址p,p**包含的地址,p*其中包含p對象的地址。
**當(dāng)您要保留內(nèi)存分配或分配,甚至在函數(shù)調(diào)用之外時(shí),也可以使用。
還要檢查這篇文章。
例:-
void allocate(int** p)
{
*p = (int*)malloc(sizeof(int));
}
int main()
{
int* p = NULL;
allocate(&p);
*p = 1;
free(p);
}

TA貢獻(xiàn)1895條經(jīng)驗(yàn) 獲得超7個贊
一種用途是從函數(shù)內(nèi)部更改指針的值。例如:
#include <stdio.h>
void swapStrings(const char **strA, const char **strB)
{
const char *tmp = *strB;
*strB = *strA;
*strA = tmp;
}
int main()
{
const char *a;
const char *b;
a = "hello";
b = "world";
swapStrings(&a,&b);
// now b points to "hello" and a points to "world"
printf("%s\n", a);
printf("%s\n", b);
}
輸出:
world
hello
- 3 回答
- 0 關(guān)注
- 504 瀏覽
添加回答
舉報(bào)