Home | | Computer Science 11th std | C++: Passing Arrays to functions

Example Program - C++: Passing Arrays to functions | 11th Computer Science : Chapter 12 : Arrays and Structures

Chapter: 11th Computer Science : Chapter 12 : Arrays and Structures

C++: 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 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.

 

C++ program to display marks of 5 students (one dimensional array)

#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;

      }

}

Output:

Display Marks:

Student 1: 88

Student 2: 76

Student 3: 90

Student 4: 61

Student 5: 69

 

Tags : Example Program , 11th Computer Science : Chapter 12 : Arrays and Structures
Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
11th Computer Science : Chapter 12 : Arrays and Structures : C++: Passing Arrays to functions | Example Program


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2024 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.