Passing a two-dimensional array to a function that displays the array's values. - C++ Data Type

C++ examples for Data Type:Array

Description

Passing a two-dimensional array to a function that displays the array's values.

Demo Code

#include <iostream>
#include <iomanip>
using namespace std;
const int ROWS = 3;
const int COLS = 4;
void display(int [ROWS][COLS]);  // function prototype
int main()//from  w  w w  .ja v a 2  s .co  m
{
   int val[ROWS][COLS] = {8,16,9,52, 3,15,27,6, 1,2,2,10};
   display(val);
   return 0;
}
void display(int nums[ROWS][COLS])
{
   int rownum, colnum;
   for (rownum = 0; rownum < ROWS; rownum++)
   {
      for (colnum = 0; colnum < COLS; colnum++) {
         cout << setw(4) << nums[rownum][colnum];
      }
      cout << endl;
   }
   return;
}

Result


Related Tutorials