+ 2

What does a 3D array look like?

I understand that 3D array would be declared as string 3DARR [x][y][z]; but who would the code look to initialize it?

18th Sep 2017, 8:52 PM
Dylan
4 odpowiedzi
+ 9
String 3DArr [x][y][z] = new String[x][y][z]{{{}}};
18th Sep 2017, 9:12 PM
David Akhihiero
David Akhihiero - avatar
+ 9
Ok perhaps just String 3DArr [x][y][z] = {{{}}}; EDIT: how did I not see that *face palm*
18th Sep 2017, 10:15 PM
David Akhihiero
David Akhihiero - avatar
+ 9
EDIT: Sample looks something like int arr[2][2][2] = {{{1, 2}, {1, 2}}, {{1, 2}, {1, 2}}}; I went overboard with the first example there with 16 elements. :facepalm: With this, accessing arr[1][0][1] will return 2 arr[0][0][0] will return 1 arr[1][1][1] will return 2 and so on.
19th Sep 2017, 6:30 AM
Hatsy Rei
Hatsy Rei - avatar
+ 5
@Yerucham... I looked into this earlier and remember there was special syntax. Unfortunately your example doesn't seem to work here on gcc: string threeDArr [1][1][1] = new string[1][1][1]{{{}}}; sorry, unimplemented: cannot initialize multi-dimensional array with intializer @Dylan - I'm just noting this in case Yerucham has another idea; I'm only at the "poke it with a stick" stage of looking.
18th Sep 2017, 9:31 PM
Kirk Schafer
Kirk Schafer - avatar