参见英文答案 >
How many levels of pointers can we have?14个
如果C(char * names [])中有指针和指针指针(char ** cur_name = names);可以有指向指针指针的指针吗?
如果C(char * names [])中有指针和指针指针(char ** cur_name = names);可以有指向指针指针的指针吗?
或者是指向指针的指针只是一个链表?也许这是一个愚蠢的问题,但我想知道答案.
解决方法
是的,您可以拥有任意数量的指针级别.
int x = 5; int *a = &x; int **b = &a; int ***c = &b; printf("%d %d %d %d\n",x,*a,**b,***c);
指向指针的指针不是链表.链表是一种结构类型,包含指向其自己类型的指针:
struct list { int data; struct list *next; };
这样你就可以将它们链接在一个列表中:
struct list three = { 3,NULL }; struct list two = { 2,&three }; struct list one = { 1,&two }; struct list head = { 0,&one };
并迭代它们:
for (struct list *node = &head; node->next; node = node->next) { printf("%d\n",node->data); }