Home | | Computer Science 11th std | C++: Passing 2"D array to a function

Example Program - C++: Passing 2"D array to a function | 11th Computer Science : Chapter 12 : Arrays and Structures

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

C++: Passing 2"D array to a function

the two-dimensional array num is passed to the function display() to produce the results.

Passing 2"D array to a function

 

C++ program to display values from two dimensional array

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

           }

}

Output:

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.

 

Function with character array as argument

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

}

output

Enter a string: welcome to C++ programming

You entered char array: welcome to C++ programming

 

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 2"D array to a function | Example Program


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

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