How to declare two dimensional (2D) fixed size array in C++

1 Answer

0 votes
#include <iostream>
#include <array>

using namespace std;

int main() {
    std::array<std::array<int, 4>, 3> arr {{{1, 2, 3, 4},{5, 6, 7, 8},{9, 0, 11, 12}}};
 
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 4; j++) {
            std::cout << arr[i][j] << " ";
        }
        std::cout << "\n";
    }
}
 
 
 
/*
run:
 
1 2 3 4 
5 6 7 8 
9 0 11 12 
 
*/

 



answered Dec 5, 2020 by avibootz
edited Dec 5, 2020 by avibootz

Related questions

1 answer 229 views
1 answer 127 views
127 views asked Dec 4, 2020 by avibootz
1 answer 142 views
1 answer 166 views
...