a) How is an array type declaration new int[10][]
evaluated? Is it evaluated
as (new int[10])[]
or as (new int[10][])
or …?
b) I’m not sure how to ask this: I know statement int[][] i = (new int[10])[]
would give us compiler error. But assuming compiler wouldn’t report an error, what kind of array type would compiler create based on this statement?
EDITED:
I apologize for not being able to make my question more comprehensive. It’s one of those questions where something is bothering me and I’m not capable of crystallizing the question in my mind enough to make some sense of it. So I ask a half assed questions hoping that replies will help me with that. Anyways, it’s a pointless question but I would still like to explain what I’ve actually meant by it:
what prompted all of this was an article from MSDN where it said
Primary expressions are divided between array-creation-expressions and primary-no-array-creation-expressions. Treating array-creation-expression in this way, rather than listing it along with the other simple expression forms, enables the grammar to disallow potentially confusing code such as
object o = new int[3][1];
which would otherwise be interpreted as
object o = (new int[3])[1];
so that got me thinking that perhaps parenthesis around different parts of this array creation expression would give compiler different instructions on the type of array it should create.
Or to put it differently, I thought that perhaps compiler follows some build-in logic ( derived from some math field ) when interpreting array creation/initialization syntax. In other words, compiler didn’t build an array due to its developers giving it specific instruction such as “when you see words new and name of some type and two pairs of square brackets ([] []), then follow these step-by-step instructions , which will tell you in full details what to do", but instead developers just build in some math related logic and from that compiler was capable deriving an array by itself, without developers giving it step by step instructions.
BTW – I do understand about jagged and rectangular arrays and how they are initialized etc ;)