这样做的原因是C声明的设计使得声明遵循使用.
如果你声明一个这样的变量:
int x[5];
Run Code Online (Sandbox Code Playgroud)
x看起来非常类似于其声明的用法:
int foo = x[0];
Run Code Online (Sandbox Code Playgroud)
这同样适用于指针:
int *y;
Run Code Online (Sandbox Code Playgroud)
用法y也类似于它的声明:
int foo = *y; /* Dereference the pointer y */
Run Code Online (Sandbox Code Playgroud)
这也适用于更复杂的声明,如下所示:
int **z[3][4]; /* z as in array of 3 arrays of 4 pointers to pointers to ints */
int foo = **z[0][0]; /* Fetch the first element of z, then fetch the first
element of the resulting array, then dereference that
pointer value, then dereference that pointer value */
Run Code Online (Sandbox Code Playgroud)
并且还适用于函数声明/指向函数的声明:
int (*f)(); /* f is a pointer to a function returning int */
int foo = (*f)(); /* Dereference the pointer f, then call it as a function. */
Run Code Online (Sandbox Code Playgroud)