Pointer syntax in C: why does * only apply to the first variable?

后端 未结 7 598
南方客
南方客 2020-12-09 16:30

The following declaration in C:

int* a, b;

will declare a as type int* and b as type int

7条回答
  •  不知归路
    2020-12-09 16:41

    Consider the declaration:

    int *a[10];
    int (*b)[10];
    

    The first is an array of ten pointers to integers, the second is a pointer to an array of ten integers.

    Now, if the * was attached to the type declaration, it wouldn't be syntatically valid to put a parenthesis between them. So you'd have to find another way to differentiate between the two forms.

提交回复
热议问题