Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
842 views
in Arrays and Structures by (49.1k points)
closed by

Explain call by value with respect to structure.

1 Answer

+1 vote
by (54.8k points)
selected by
 
Best answer

When a structure is passed as argument to a function using call by value method, any change made to the contents of the structure variable inside the function to which it is passed do not affect the structure variable used as an argument.

#include

using namespace std;

struct Employee

{

char name[50];

int age;

float salary;

};

void printData(Employee); // Function declaration

int main()

{

Employee p;

cout << "Enter Full name:";cin>>p.name;

cout << "Enter age :";cin>>p.age;

cout << "Enter salary:";cin>>p.salary;

// Function call with structure variable as an argument

printData(p);

return 0;

}

void printData(Employee q)

{

cout << “\nDisplaying Information.” << endl; 

cout << “Name:” << q.name << endl;

cout <<”Age:” << q.age << endl;

cout << “Salary:” << q.salary;

}

Output:

Enter Full name: Kumar

Enter age : 55

Enter salary : 34233.4

Displaying Information.

Name : Kumar

Age : 55

Salary : 34233.4

In the above example, a structure named Employee is declared and used. The values that are entered into the structure are name, age and salary of a Employee are displayed using a function named print Data(). The argument for the above function is the structure Employee. The input can be received through a function named readData().

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

...