Structure and Function in C++
Jan 12, 2022
Structure variables is pass to a function and return in a same way as regular parameter
Passing structure to function in C++
A structure variable is passed to a function in same way as normal argument
Program of passing structure to function in C++
#include <iostream>
using namespace std;struct Emp {
char name[50];
int age;
float salary;
};void displayData(Emp); // Function declarationint main() {
Emp e; cout << "Enter name: ";
cin.get(e.name, 50);
cout << "Enter age: ";
cin >> e.age;
cout << "Enter salary: ";
cin >> e.salary; displayData(e); return 0;
}void displayData(Emp e) {
cout << "\n Information." << endl;
cout << "Name: " << e.name << endl;
cout <<"Age: " << e.age << endl;
cout << "Salary: " << e.salary;
}