Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Passing a 2D array to a C++ function
Arrays can be passed to a function as an argument. In this program, we will perform to display the elements of the 2 dimensional array by passing it to a function.
Algorithm
Begin The 2D array n[][] passed to the function show(). Call function show() function, the array n (n) is traversed using a nested for loop. End
Example Code
#include <iostream>
using namespace std;
void show(int n[4][3]);
int main() {
int n[4][3] = {
{3, 4 ,2},
{9, 5 ,1},
{7, 6, 2},
{4, 8, 1}};
show(n);
return 0;
}
void show(int n[][3]) {
cout << "Printing Values: " << endl;
for(int i = 0; i < 4; ++i) {
for(int j = 0; j < 3; ++j) {
cout << n[i][j] << " ";
}
}
}
Output
Printing Values: 3 4 2 9 5 1 7 6 2 4 8 1
Advertisements