What is the best way to initialize a large 2D array with 0 in the constructor? I would like to do this without having to loop through my array, if possible.
Alternatively, use a std::vector instead of an array.
std::vector<std::vector<int>> vec2d(100, std::vector<int>(50, 0));
The resulting two-dimensional vector will contain 100 vectors, each containing 50 zeros.
use memset. For example:
int a[10][10];
memset(a, 0, sizeof(int)*10*10);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With