Could you please give me a little help on the following problem

Suppose we have the following pseudocode:

       var i, j : integer;
       procedure P (k,m:integer);

What are the values of i and j at the end of the program fragment if (a) both parameters are passed by value? (b) both parameters are passed by reference. ??

Adam, Thank you for your question. This appears not to be a C++ language question, but I will try to answer anyway.

Arguments "passed by value" are simply treated as values, not as memory locations. They are usually passed to a function via cpu registers. Arguments "passed by reference" are passed to a function as addresses of memory locations.

The main difference in practice is that

1. Changing a "by value" argument does not change the variable that was passed as the actual argument. In fact, some compilers prohibit this.

2. Changing a "by reference" argument changes the variable that was passed as the actual argument.

Note that an arbitrarily complicated expression (of the correct datatype) may be passed "by value" but not "by reference", since it is not a memory location. Some compilers (such as for Basic or Fortran) will evaluate such an expression and store it in a memory location, then pass a reference to that location. This is not pure "pass by reference".

David Spector


All Answers

Answers by Expert:

Ask Experts


David Spector


Highly knowledgeable in the C++ language, Visual C++ (MSVC), Windows API, documentation and other quality-assurance techniques, and debugging. Knowledgeable in MFC, COM, GUI design, and object-oriented design.


I have been a software engineer since 1965. I have been published. My specializations have been: biomedical programming, compiler implementation, and many kinds of Windows programming. I don't do Databases or other business-oriented stuff.

Windows?/DOS Developer's Journal, ACM SIGPLAN Notices, and Computer Science Press.

ICCP Systems Programming Certification
Master's degree equivalent in Computer Science

©2016 About.com. All rights reserved.