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

Explain the terms- substitutability and extensibility, Explain the terms- S...

Explain the terms- Substitutability and Extensibility Substitutability - The objects of a properly derived class can be safely and easily substituted for an object of its

Arrays, #question.Write a c++ program to accept and print a 1_d array

#question.Write a c++ program to accept and print a 1_d array

Declaring Integer variables with an example, How do you declare an integer ...

How do you declare an integer variable? Explain with an example.

StACK, Q. Explain that how do we implement two stacks in one array A[1..n] ...

Q. Explain that how do we implement two stacks in one array A[1..n] in such a way that neither the stack overflows unless the total number of elements in both stacks together is n.

C program for function of merge , C Program for FUNCTION OF MERGE #inc...

C Program for FUNCTION OF MERGE #include conio.h> #include stdio.h> char cot(char a[],char b[]); void main() {           char a[50],b[50];           clrscr()

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 -

How can I fix this to, Write a program consisting of two functions (plus ma...

Write a program consisting of two functions (plus main). The first function should read in a number and then pass this back to main. This value should then be passed into a secon

Vision based simultaneous mapping and localization, Project Description: ...

Project Description: Design and prepare software that can navigate a mobile robot using SLAM technique using vision sensor (camera). Skills required are C Programming, Engine

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