Java既支持这两种语言,为什么不支持C呢?
我认为int []arr
更容易阅读。
有什么特殊的原因吗?
发布于 2018-01-18 23:16:59
这样做的原因是C声明的设计使得declaration follows usage。
如果你像这样声明一个变量:
int x[5];
x
的用法与其声明非常相似:
int foo = x[0];
这同样适用于指针:
int *y;
y
的用法也类似于它的声明:
int foo = *y; /* Dereference the pointer y */
这也适用于更复杂的声明,比如:
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 */
也适用于函数声明/指向函数的指针声明:
int (*f)(); /* f is a pointer to a function returning int */
int foo = (*f)(); /* Dereference the pointer f, then call it as a function. */
https://stackoverflow.com/questions/48324237
复制相似问题