Pointers/Memory Allocation   «Prev  Next»
Lesson 16 Dynamic multidimensional arrays
Objective The main() function

main() function of the C++ dynamic multidimensional array program.

Here is main(). Notice that findmax() is applied to different-sized dynamically allocated structures.
#include <iostream.h>

int main(){
  twod a, b;
  int  i, j;
    
  allocate(2, 3, a);
  allocate(4, 6, b);
  for (i = 0; i < a.column_size; ++i)
     for (j = 0; j < a.row_size; ++j)
        a.base[i][j] = i * j ;
  for (i = 0; i < b.column_size; ++i)
     for (j = 0; j < b.row_size; ++j)
        b.base[i][j] = i * j ;
  cout << findmax(a) <<
    " max in size 2 * 3 " << endl;
  cout << findmax(b) <<
    " max in size 4 * 6 " << endl;
}

Review of the main() function

int main()