Passing
2"D array to a function
#include <iostream>
using namespace std;
void display (int n[3][2]);
int main()
{
int num[3][2] = { {3,
4}, {9, 5}, {7, 1} };
display(num);
return 0;
}
void display(int n[3][2])
{
cout <<
"\n Displaying Values" << endl;
for (int i=0;
i<3; i++)
{
for (int j=0;
j<2; j++)
{
cout <<
n[i][j] << " ";
}
cout <<
endl << endl;
}
}
Displaying Values
3 4
9 5
7 1
In
the above program, the two-dimensional array num is passed to the function
display() to produce the results.
#include <iostream>
using namespace std;
int main()
{
char str[100];
void display(char s[]);
cout<<
"Enter a string: ";
getline(cin, str);
display(str);
return 0;
}
void display(char s[])
{
cout<< "You entered char array: " << s
<<endl;
}
Enter a string: welcome to C++ programming
You entered char array: welcome to C++ programming
Related Topics
Privacy Policy, Terms and Conditions, DMCA Policy and Compliant
Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.