For statically sized arrays, use std::array. For dynamically sized arrays use std::vector. Don't ever use raw C arrays unless some weird situation forces it on you.
If you need a multi dimensional array, you can of course use std::vector<std::vector<int>>
or similar for std::array
. This is easy and convenient since you can do myarray[row][column]
(and possibly good enough). But a better performing option is usually to just declare a 1D std::vector<int>
with a size of "dimension 1 * dimension 2" and then, when indexing into it, do myvector[row_number * size_of_row + column]
. Treating a 1D array as a 2D one is as easy as that and it is likely to perform better since it's friendlier to your CPUs prefetcher and cache hierarchy.
As for declaring a function to accept such arrays - it's straight forward. For example:
void f(const std::array<int, 666>& myarray);
void f(const std::array<std::array<int, 42>, 666>& myarray);
void f(const std::vector<int>& myarray);
void f(const std::vector<std::vector<int>>& myarray);