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

Msp, A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X...

A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X’ P(1) = ‘Y’ P(2) = ‘Z’ P(n) = P(n-2) + P(n-3), n>2 where + denotes string concatenation. For a string of t

My program, palindrome program with minimum character replacements

palindrome program with minimum character replacements

Assyrian keyboard for android, Project Description: I want an app that t...

Project Description: I want an app that the user can download it from the play store and use it as a keyboard for texts and writing. Just like the Samsung keyboard and the arabi

Change to palindrome, convert string s into palindrome by doing character r...

convert string s into palindrome by doing character replacement

The car’s measurements are illustrated, The car’s measurements are illustra...

The car’s measurements are illustrated, using two arrays. Array 1 = {L, R, L, R, R, L, R, R, L, R, R, L, R, L, L, R, Z}

I need website with built in scraper, I need Website with built in scraper ...

I need Website with built in scraper Project Description: The coding skills mentioned above are just possibly ones that will be used. Skills required are ASP, C++ Programm

C program count characters words with space & without space , v\:* {behavio...

v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} Normal 0

Arrays, how to declare multi dimensional array

how to declare multi dimensional array

Salary of an employe, basic salary of an employe.the allowence are House r...

basic salary of an employe.the allowence are House rent 20% of basic salary Medical allowence is 10% of basic salary conveyence allowence is 10% calculate anrd display gross salar

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