// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
#include <iostream>

using namespace std;

void init1(int *a,int n,int m)
{
   for(int i=0; i<n; i++) for(int j=0; j<m; j++) a[i*m+j]=1;
   return;
}

void show1(int *a,int n,int m)
{
   for(int i=0; i<n; i++) {
      for(int j=0; j<m; j++) cout << " " << a[i*m+j];
      cout << endl;
   }
   return;
}

void init2(int **b,int n,int m)
{
   for(int i=0; i<n; i++) for(int j=0; j<m; j++) b[i][j]=2;
   return;
}

void show2(int **b,int n,int m)
{
   for(int i=0; i<n; i++) {
      for(int j=0; j<m; j++) cout << " " << b[i][j];
      cout << endl;
   }
   return;
}

typedef int twodim[][3]; // <-------- fixed second dimension

void init3(twodim c,int n,int m)
{
   for(int i=0; i<n; i++) for(int j=0; j<m; j++) c[i][j]=3;
   return;
}

void show3(twodim c,int n,int m)
{
   for(int i=0; i<n; i++) {
      for(int j=0; j<m; j++) cout << " " << c[i][j];
      cout << endl;
   }
   return;
}

int main()
{
   int n = 2;
   int m = 3;
   int *a = new int[n*m];
   init1(a,n,m);
   show1(a,n,m);
   int **b = new (int *)[n];
   for(int i=0; i<n; i++) b[i]=new int[m];
   init2(b,n,m);
   show2(b,n,m);
   twodim *c = new twodim[2];
   init3(*c,n,m);
   show3(*c,n,m);
}

