Explain passing and returning objects, C/C++ Programming

Assignment Help:

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);

 }

 


Related Discussions:- Explain passing and returning objects

Padovan sequence, #write a program that counts the number of occurances of ...

#write a program that counts the number of occurances of the string in the n-th padovan string p(n)

When should you employ multiple inheritance?, Q: When should you employ mul...

Q: When should you employ multiple inheritance? A:There  are  three  acceptable  answers:-  "Rarely," "Never," and  "while  the  problem  domain cannot be modeled accurately any

Control structures in cpp, Control structures The control structures app...

Control structures The control structures appear in both structured programming languages as well as object oriented programming languages.  The three constructs used are: i)

Doubt!, find the greater of the two variables, without using conditional lo...

find the greater of the two variables, without using conditional loops or ternary operators?

Float number, We can combine more than one variable on the same line i.e. ...

We can combine more than one variable on the same line i.e.   float number1,number2,number3; etc Sometimes we want to mix the variable types used on the same line, this could

Decode the code, smugglers transfer the messages from one to another by usi...

smugglers transfer the messages from one to another by using the mobile

Super ascii string checker, Program which can check the given string is su...

Program which can check the given string is super ascii or not

Strings, write a c program to find input string using strlen(), strcpy(), s...

write a c program to find input string using strlen(), strcpy(), strcat(),strncat(), strcmp().

Menus, create a shopping cart in c++

create a shopping cart in c++

How private instance of a class can be assigned values, Question 1: (a)...

Question 1: (a) Explain clearly the following concepts using suitable examples of your own:- (i) concrete class v/s abstract class (ii) constructor v/s over

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd