在数组声明INT [] K,I和INT [],I K; [英] in array declaration int[] k,i and int k[],i;
问题描述
在声明数组我们可以用括号标识的任何一方,但在这样的:
While declaring array we can use brackets any side of the identifier but in the case:
int[] k,i;
和
int k[],i;
有将两种不同的方式来考虑。这是第一个创建两个数组k和我。
该第二个创建一个数组k和正常的变量i。这是什么行为?
It will be considered in two different ways. That is first one creates two arrays k and i. that second one creates an array k and a normal variable i. What is this behavior?
编辑:在Java中我们通常preFER第一类型声明。但在这种情况下,我们不能建立在单个语句的数组和基本变量。
in java usually we prefer first type of declaration. but in this case we cant create an array and a primitive variable in the single statement.
推荐答案
我的猜的是以下内容:
声明 INT [] K
更符合逻辑的,因为它声明 K
是一个的阵列的 INT
的。因此,它是preferred(?)式中的Java
The declaration int[] k
is more logical, because it declares k
to be an array of int
. Therefore, it is the preferred (?) style in Java.
时int k []
,在另一方面,被宣告此阵中C方式(K&安培; R有着不同的理念,当它来声明语法 - 他们通缉声明模仿的访问应用于变量),缓解C程序员转型,这个语法也被允许的 - 又何妨呢
int k[]
, on the other hand, was the C way of declaring this array (K&R had a different philosophy when it came to declaration syntax – they wanted declarations to mimic access to the variable) and to ease the transition for C programmers, this syntax was also allowed – no harm done.
现在,在你上面的说法你已经链接两个声明。在第一种情况下,这两个变量声明为同一类型的 - 这显然是 INT []
。然而,在第二code这种行为是反直觉(以及从C的行为也不同),因此具有其他语义。
Now, in your above statement you have chained two declarations. In the first case, both variables are declared with the same type – which is clearly int[]
. However, in the second code this behaviour would be counter-intuitive (and also different from C’s behaviour), and therefore has other semantics.
请记住,这纯粹是一种猜测。
Keep in mind that this is purely a guess.
这篇关于在数组声明INT [] K,I和INT [],I K;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!