I have a two dimensional std array such as, array<array<int, 9>, 9> tbl;
How to initialize it with the same value such as -1? If I just want it to be zero-initialized, what is the best way to it?
I have a two dimensional std array such as, array<array<int, 9>, 9> tbl;
How to initialize it with the same value such as -1? If I just want it to be zero-initialized, what is the best way to it?
Copyright © 2021 Jogjafile Inc.
As @PaulMcKenzie has stated, there isn't a single best way to do something.
For zero initializing the entire array, you can probably use aggregate initialization method.
This method only works for zero-initialization of the array.
But if you want to initialize the array with a custom number throughout, you would need to iterate through all the elements and assign them manually.