+1 vote
in Class 12 by kratos

Describe how objects can be used as function arguments.

1 Answer

+5 votes
by kratos
 
Best answer

The objects of same class can be passed as arguments to a function. This is explained with an example,
class rup

in the above example, rup is the class, n1 and n2 are data members, readdata(), printdata() and multi() are member functions with r1, r2 are the function argument of object type.
The line obj3.multi (obj1, obj2); pass obj1 and obj2 which are the objects of class rup type. In the statement
n1 = r1.n1 r1.n2;
n2 = r2.n1
r2.n2;
r1.n1 is accessing data member n1 of object r1 and r1.n2 is accessing data member n2 of object r1 and their product is stored in data member n1 and same for n2 in the second line which is the member of obj3 object.
The obj3.printdata() gives out the result stored in the n1 and n2.

...