int[5,5,5,5]

Oct 18, 2012 at 12:37am
Is it legal to declare multidimensional array like that?

int *a=new int[5,5,5,5];

It translated without an error.
Oct 18, 2012 at 12:42am
It translated without an error.

And int[5,5,5,5] translates to int[5].
Oct 18, 2012 at 1:03am
Thanks. I'm just wondering why did they do that? Very strange.
Oct 18, 2012 at 2:12am
closed account (o1vk4iN6)
You can only pass one parameter to the operator[] function. It is actually read like this (because the comma is also an operator):

int *a=new int[ (5,5,5,5) ];

So the last value will be what it actually takes as a parameter.

To allocate a multi-dimension array you do it like this:

int (*a)[5] = new int[5][5];
Last edited on Oct 18, 2012 at 2:13am
Oct 18, 2012 at 1:01pm
Thanks, xerzi.
Oct 18, 2012 at 4:00pm
int[5,5,5,5] is not a multidimensional array. It is a one-dimensional array the size of which is specified with an expression using the comma operator..
To declare a multidimensional array you should write

int[5][5][5][5];

Oct 18, 2012 at 4:02pm
Also see the "Comma operator ( , )" section of

Operators
http://www.cplusplus.com/doc/tutorial/operators/

The comma operator is also known as the sequence operator.

Andy
Topic archived. No new replies allowed.