Is it legal to declare multidimensional array like that?

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

It translated without an error.
It translated without an error.

And int[5,5,5,5] translates to int[5].
Thanks. I'm just wondering why did they do that? Very strange.
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
Thanks, xerzi.
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


Also see the "Comma operator ( , )" section of


The comma operator is also known as the sequence operator.

Topic archived. No new replies allowed.