MAO-EYE 2012-04-10 10:34 采纳率: 66.7%
浏览 246

我们可以有多少级的指针?

How many pointers (*) are allowed in a single variable?

Let's consider the following example.

int a = 10;
int *p = &a;

Similarly we can have

int **q = &p;
int ***r = &q;

and so on.

For example,

int ****************zz;

转载于:https://stackoverflow.com/questions/10087113/how-many-levels-of-pointers-can-we-have

  • 写回答

10条回答 默认 最新

  • 关注

    Theoretically:

    You can have as many levels of indirections as you want.

    Practically:

    Of course, nothing that consumes memory can be indefinite, there will be limitations due to resources available on the host environment. So practically there is a maximum limit to what an implementation can support and the implementation shall document it appropriately. So in all such artifacts, the standard does not specify the maximum limit, but it does specify the lower limits.

    Here's the reference:

    C99 Standard 5.2.4.1 Translation limits:

    — 12 pointer, array, and function declarators (in any combinations) modifying an arithmetic, structure, union, or void type in a declaration.

    This specifies the lower limit that every implementation must support. Note that in a footenote the standard further says:

    18) Implementations should avoid imposing fixed translation limits whenever possible.

    评论

报告相同问题?