suppose I have this code :
int arr[] = {{1, 4}, {2}, {3, 2, 6}};
how do I count the number of arrays within an array, which in this case would be 3. if the code dosen't work is there a way to get the answer with other methods?
i've searched on google and read articles
A one-dimsional array can not contain other arrays as its elements.
You could use for example
std::initializer_list<int>as the element type instead of the typeint.Here is a demonstration program.
The program output is
Otherwise you could declare a two-dimensional array like for example
In this case each element of the array has the type
int[3].Again you can use the standard C++ function
std::sizedeclared in the header<iterator>to get the number of elements in the array. Or you could simply writeNwill be equal to3.Another approach is to use standard container
std::vector.For example
You may use the same standard function
std::size( arr )or member function size likearr.size().