While declaring array we can use brackets any side of the identifier but in the case:
int[] k,i;
and
int k[],i;
My guess is the following:
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[]
, 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.
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.