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
4.5k views
in Computer by (26.0k points)

How are objects passed as arguments to a function? Give an example.

1 Answer

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

The function arguments can be objects and passed in two ways namely pass by value and pass by reference. In pass by value, a copy of the object as actual argument is passed to the function and formal arguments of function which of class type receive the copy of the actual argument and process it.

Any changes made in the formal argument inside the function body will not reflect in actual arguments.
In pass by reference, the address of an object is passed as actual argument and formal argument holds the address of objects of actual arguments. Any changes made to formal argument in the function body will reflect in the actual argument since it holds the actual address of actual argument objects.

The pass by value example:
The objects of same class can be passed as arguments to a function.

The line obj3.multi (obj1, obj2); pass obj1 and obj2 which are the objects of class rup type.

Related questions

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.

Categories

...