how to initialize 2d array with values c++
#include <iostream>
const int ROWS = 3;
const int COLS = 4;
int main() {
int arr[ROWS][COLS] = {
{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12}
};
// Accessing and printing the elements of the 2D array
for (int i = 0; i < ROWS; ++i) {
for (int j = 0; j < COLS; ++j) {
std::cout << arr[i][j] << " ";
}
std::cout << std::endl;
}
return 0;
}