I'm still confused. Can I do this?
int x[y[3]]
Array within array?
Is that the correct format?
Thank you!
I'm still confused. Can I do this?
int x[y[3]]
Array within array?
Is that the correct format?
Thank you!
int x[y[3]];
is valid if y[3]
is an integral constant expression, and it will declare an array of y[3]
elements. Otherwise it’s invalid.
If you are looking for a 2D array, try the following:
#include <array>
std::array<std::array<int, 3>, 4> x;
If you want less pain to go through, you can look at Boost.MultiArray, as suggested by Cat Plus Plus.
Even with the assumption that y[3]
is of an integer type (otherwise it makes no sense), VLA (variable length arrays) are not supported in c++. They are part of C99, but not c++. Therefore, your code is not good.
Some compilers do support VLA, but only as an extension.
It would be something like this
int[,] myArray = new int[1][2];
myArray[0][1] = 1;
myArray[1][1] = 1;