Horje
passing a 2d array cpp Code Example
passing a 2d array cpp
#include <iostream>
#include <vector>
using namespace std;

typedef vector< vector<int> > Matrix;

void print(Matrix& m)
{
   int M=m.size();
   int N=m[0].size();
   for(int i=0; i<M; i++) {
      for(int j=0; j<N; j++)
         cout << m[i][j] << " ";
      cout << endl;
   }
   cout << endl;
}


int main()
{
    Matrix m = { {1,2,3,4},
                 {5,6,7,8},
                 {9,1,2,3} };
    print(m);

    //To initialize a 3 x 4 matrix with 0:
    Matrix n( 3,vector<int>(4,0));
    print(n);
    return 0;
}




Cpp

Related
c++ allocate dynamic with initial values Code Example c++ allocate dynamic with initial values Code Example
Python ord() Code Example Python ord() Code Example
c++ qt QFuture Code Example c++ qt QFuture Code Example
typedef Code Example typedef Code Example
How to write String in C++ Code Example How to write String in C++ Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9