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. */
发布于 2018-01-18 23:08:35
Java是从C借来的,而不是从C借来的。
显然,java认为这将是对C语法的改进。
但是,通常情况下,定义某些内容的方式越多,编译器解析代码就越困难。由于c
是在20世纪70年代开发的,计算能力有限,所以简单性是他们的首要要求。
在20世纪90年代,当他们开发Java时,这就不是什么大问题了。
https://stackoverflow.com/questions/48324237
复制相似问题