How to initialize 3D array in C++

arrays, c, c++, multidimensional-array

Solution

The array in your question has only one element, so you only need one value to completely initialise it. You need three sets of braces, one for each dimension of the array.

int min[1][1][1] = {{{100}}};

A clearer example might be:

int arr[2][3][4] = { { {1, 2, 3, 4}, {1, 2, 3, 4}, {1, 2, 3, 4} },
                     { {1, 2, 3, 4}, {1, 2, 3, 4}, {1, 2, 3, 4} } };

As you can see, there are two groups, each containing three groups of 4 numbers.

Problem

How do you initialize a 3d array in C++ ``` int min[1][1][1] = {100, { 100, {100}}}; //this is not the way ```

Original source

Related problems