Argument Passing in DM and C++ == Call-by-value versus Call-by-reference == - Practical Electron Microscopy and Database - - An Online Book - |
||||||||||||||
Microanalysis | EM Book http://www.globalsino.com/EM/ | ||||||||||||||
================================================================================= | ||||||||||||||
There are two ways that a computer language can pass
an argument to a subroutine: C++, by default, uses the call-by-value method for passing arguments. Therefore, in general, code inside a function cannot alter the arguments which are used to call the function. Table 1123a. Call-by-value method for passing arguments.
◆ Call-by-reference. In this way, a subroutine can be passed arguments. The address of an argument (not its value) is copied into the parameter. Inside the subroutine, this address is used to access the actual argument which is specified in the call. Therefore, the changes made to the parameter will affect the argument used to call the subroutine. Even though C++'s default passing convention is call-by-value, it is still possible to manually create a call-by-reference by passing the address of an argument, e.g. a pointer to the argument, to a function. Then, it is possible for code inside the function to change the value of the argument outside of the function. However, it is necessary to declare the parameters as pointer types. Note that these pointer types for call-by-reference is not available in DM interface. Table 1123b. Call-by-reference method for passing arguments.
Table 1123c. Call-by-value versus call-by-reference for argument passing.
|
||||||||||||||
================================================================================= | ||||||||||||||
|
||||||||||||||