Calender Man
Calender Man

Reputation: 23

Quick array conversion from Java to C++

How would I use something like:

int array[][] = {{0,0,0},{1,0,0}};

...which is Java code in C++?

Upvotes: 1

Views: 109

Answers (2)

Óscar López
Óscar López

Reputation: 236034

Like this:

int array[2][3] = {{0,0,0},{1,0,0}};

Or this, because the first dimension is optional:

int array[][3] = {{0,0,0},{1,0,0}};

And by the way, in Java the idiomatic way to declare the same array is this:

int[][] array = {{0,0,0},{1,0,0}}; // [][] goes before the variable name

Upvotes: 3

Joseph Mansfield
Joseph Mansfield

Reputation: 110668

You would do it like so:

int array[][3] = {{0,0,0},{1,0,0}};

Only the first dimension may be omitted.

Upvotes: 3

Related Questions