Cpp Program of Passing 2D array to Function

ad+1

Passing multidimensional array to function is almost same as that of passing single dimensional array. In this tutorial i will show you how to pass multidimensional array to function and also in future tutorials i will show you how to pass multidimensional array to function using pointers. So let start.


Program:

// Program By http://solutionscpp.blogspot.com
// Author Mansoor Ahmed
// GMail ID: secguy000@gmail.com

#include<iostream>
using namespace std;

void filling(int arr[5][5]);    //Function Prototype
void printing(int arr[5][5]);

int main()
{
int arr[5][5]={};  // Null Array

filling(arr);  //Function Call
printing(arr);

}


void filling(int arr[5][5])
{
//Filling 2D array
cout<<"Filling Data: " <<endl;

for(int i=0; i<5; i++)
{
for(int j=0; j<5; j++)
{
cin>>arr[i][j];
}
}

}


void printing(int arr[5][5])
{
//Printing 2D array
cout<<"\nPrinting Data: " <<endl;

for(int i=0; i<5; i++)
{
for(int j=0; j<5; j++)
{
cout<<arr[i][j];
}
}

}



Output:



4 comments: Leave Your Comments