Oct 18, 2012 at 12:37am UTC
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 1:03am UTC
Thanks. I'm just wondering why did they do that? Very strange.
Oct 18, 2012 at 2:12am UTC
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 UTC
Oct 18, 2012 at 4:00pm UTC
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];