Passing
Arrays to functions
In
C++, arrays can be passed to a function as an argument. To pass an array to a
function in C++, the function needs the array name as an argument.
Passing
a two-dimensional array to a function
Write
a program to display marks of 5 students by passing one-dimensional array to a
function.
#include <iostream>
using namespace std;
void display (int m[5]);
int main()
{
int marks[5]={88, 76,
90, 61, 69};
display(marks);
return 0;
}
void display (int m[5])
{
cout <<
"\n Display Marks: " << endl;
for (int i=0; i<5;
i++)
{
cout <<
"Student " << i+1 << ": " <<
m[i]<<endl;
}
}
Display Marks:
Student 1: 88
Student 2: 76
Student 3: 90
Student 4: 61
Student 5: 69
Related Topics
Privacy Policy, Terms and Conditions, DMCA Policy and Compliant
Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.