Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this a valid 2D Array definition in C++?

I just saw something like this in a C++ code (that compiles and probably works in VS2010):

int *p = new int[8, 6];
p[2, 3] = 5;

Is this a new notation for creating multidimensional arrays in C++? Or am I missing something? As far as I remember, arrays are declared this way [a][b] not [a, b] in C++. It would be highly appreciated if you could explain this code.

Thanks.

like image 245
Joe Bank Avatar asked Apr 28 '12 13:04

Joe Bank


1 Answers

This is valid syntax, but it doesn't specify 2D arrays. It's using the comma operator, so it's equivalent to:

int *p = new int[6];
p[3] = 5;
like image 128
Oliver Charlesworth Avatar answered Oct 19 '22 22:10

Oliver Charlesworth