You are here:

C++/call by referance keeps the...


call by referance keeps the last value of the variable (yes or no)

when we use recursion we can use for with it

or just return

thank you for helping me

This is _not_ a C++ question - it is a general programming question.

Call by reference passes a reference to a variable, so modifying the variable referred to by such a parameter within a function call modifies the variable referred to that is outside the function call. So I suppose the answer is yes the last value is kept. Although this only made sense to me when I realised you are talking about recursion as in general your phrasing is odd for the feature you are describing. Some help on this point earlier in the question would have made it easier for me to understand your question - which you want me to do so that I provide a relevant answer...

I suppose you can use loops with recursion,  including for loops. It would depend on the requirements at the time.

However, in simple terms, with a recursive implementation you make another recursive call or just return where in an iterative implementation you would continue iterating (looping) or terminate the loop.

Beyond this level, what else you are doing may involve just simple conditions or it may involve loops or even further recursion. You might not even be aware of such things. For example if you output some data to the console then I would guess that some form of looping is involved to iterate around the data to be output at various points. Consider:

       std:cout << "The value is " << value << ".\n";

This might be printed as:

       The value is 1234.

The characters that make up the text will most likely have to be copied between various buffers - which would almost certainly involve loops. The number would have to be converted from, say an int to a sequence of characters which may involve loops or might even involve recursion.  


All Answers

Answers by Expert:

Ask Experts


Ralph McArdell


I am a software developer with more than 15 years C++ experience and over 25 years experience developing a wide variety of applications for Windows NT/2000/XP, UNIX, Linux and other platforms. I can help with basic to advanced C++, C (although I do not write just-C much if at all these days so maybe ask in the C section about purely C matters), software development and many platform specific and system development problems.


My career started in the mid 1980s working as a batch process operator for the now defunct Inner London Education Authority, working on Prime mini computers. I then moved into the role of Programmer / Analyst, also on the Primes, then into technical support and finally into the micro computing section, using a variety of 16 and 8 bit machines. Following the demise of the ILEA I worked for a small company, now gone, called Hodos. I worked on a part task train simulator using C and the Intel DVI (Digital Video Interactive) - the hardware based predecessor to Indeo. Other projects included a CGI based train simulator (different goals to the first), and various other projects in C and Visual Basic (er, version 1 that is). When Hodos went into receivership I went freelance and finally managed to start working in C++. I initially had contracts working on train simulators (surprise) and multimedia - I worked on many of the Dorling Kindersley CD-ROM titles and wrote the screensaver games for the Wallace and Gromit Cracking Animator CD. My more recent contracts have been more traditionally IT based, working predominately in C++ on MS Windows NT, 2000. XP, Linux and UN*X. These projects have had wide ranging additional skill sets including system analysis and design, databases and SQL in various guises, C#, client server and remoting, cross porting applications between platforms and various client development processes. I have an interest in the development of the C++ core language and libraries and try to keep up with at least some of the papers on the ISO C++ Standard Committee site at


©2016 All rights reserved.