Explain the returning references from functions, C/C++ Programming

Assignment Help:

Returning References from Functions

Just as in passing the parameters by reference, returning a reference also doesn't return back a copy of the variable , instead an alias is returned.

e.g.

                int &func(int &num)

                 {

                                :

                                :

                                return(num);

                 }

                void main()

                 {

                   int n1,n2;

                                :

                                :

                                n1 = fn( n2);

                 }

Notice that the function header haves an ampersand (&) before the function name. This is how a function is made to return reference variable. In this case, it takes a reference to an integer as its argument and returns a reference to an integer. This facility can be very useful for returning objects and even structure variables.

 


Related Discussions:- Explain the returning references from functions

C++, padovan string c++ program

padovan string c++ program

C program for maximum no, C Program for MAXIMUM NO, MINIMUM NO AND SORTING ...

C Program for MAXIMUM NO, MINIMUM NO AND SORTING   void main() {           int i,j,t;           int a[5];           clrscr();           for(i=0;i

Define a complex number in c program, Define a complex number in c program:...

Define a complex number in c program: class complex                                 {                                   private:                                 in

How to write a global inline function, How to write a global inline functio...

How to write a global inline function First, let's get away from member functions for a moment and consider a global function.  To make a request that this function be in line:

Crossoword puzzle, find wether specific word is inside a pool of word and w...

find wether specific word is inside a pool of word and what is the direction e.g. north

C code, how can i easily make a program?

how can i easily make a program?

Define some features of external storage class in c program, Define some fe...

Define some features of external storage class in c program? The features of an external storage class variable are as follows: Storage - memory Default initial value -

I want auto-rank script, Project Description: I play this game called mo...

Project Description: I play this game called mobstar (mobstar) and I would like the program to grade my account for me. It would require doing a crime, GTA, jail busting, lead a

Describe run-time type identification, The ability to verify at run time th...

The ability to verify at run time the type of an object by using the typed operator or the dynamic_cast operator.

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