passing and returning objectsobjects can be


Passing and Returning Objects

Objects can be passed to a function and returned back just like normal variables. When an object is passed by content, the compiler makes another object as a formal variable in the called function and copies all the data members from the actual variable to it. Objects can also be passed by address, which will be discussed later.

e.g.

                class check

                 {

                  public :

                check add(check);

                void get()

                                 {

                                   cin >> a;

                                 }

                                void put()

                                 {

                                   cout << a;

                                 }

                  private :

                                int a;

                 };

void main()

 {

  check c1,c2,c3;

  c1.get();

  c2.get();

  c3 = c1.add(c2);

  c3.put();

 }

check check :: add ( check c2)

 {

  check temp;

temp.a = a + c2.a;

return ( temp);

 }

 

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: passing and returning objectsobjects can be
Reference No:- TGS0309361

Expected delivery within 24 Hours