【发布时间】:2020-06-24 07:57:42
【问题描述】:
在 C 语言中,我知道我们可以用指针来做到这一点:
int *p; /* an int pointer (ptr to an int) */
int **pp; /* a pointer to an int pointer (ptr to a ptr to an int) */
甚至:
int **app[]; /* an array of pointers to int pointers */
int (**ppa)[]; /* a pointer to a pointer to an array of ints */
int (**ppf)(); /* a pointer to a pointer to a function returning an int */
int *(*pap)[]; /* a pointer to an array of int pointers */
int **fpp(); /* a function returning a pointer to an int pointer */
但是我们可以做类似三个指向无限的事情吗?例如:
int ***ppp; /* a pointer to a pointer to an int pointer */
int ****pppp; /* a pointer to a pointer to a pointer to an int pointer */
...以此类推直到无穷大。
我们可以拥有的指向指针的指针数量是否有上限?如果有,上限是多少?
【问题讨论】:
-
理论上没有限制。实际上,编译器可能有一个可能远高于所需的限制。此外,诸如
int ***foo之类的三个以上的间接寻址很少(如果不是从不)有用。另请阅读this -
@RobertSsupportsMonicaCellio 很棒的建议……我会做的。
-
这是一个有趣的问题,我点了它,但它一直是asked and answered already
-
@ryyker 是的,我也想知道我是否没有在其他任何地方看到它,但正忙着思考它,并且没有太多的灵感来寻找它,虽然我找到了它,但你更快; -)。
标签: c pointers language-lawyer limit