Explain the following – (i) Pass by value (ii) Pass by address (iii) Pass by reference.

Explain the following – (i) Pass by value (ii) Pass by address (iii) Pass by reference.

Ans.  (i) Pass by Value – This is the default mechanism of parameter passing. Pass by value mechanism does not change the contents of the argument variable in the calling function (caller), even if they are changed in the called function (callee); because the content of the actual parameter in a caller is copied to the formal parameter in the callee. The formal parameter is stored in the local data area of the callee changes to the parameter within the function will effect only the copy (formal parameters ) and will have no effect the actual argument.

(ii)Pass by Address – C++ provide another means of passing values to a function known as by pass address. Instead of passing the value, the address of the variable is passed. In the function, the address of the argument is copied into memory location instead of the value. The de-referencing operator is used to access the variable in the called function.

(iii)Pass by Reference – Passing parameters by reference has the functionality of pass by pointer and the syntax of call by value. Any modifications made through the formal pointer parameters is also reflected in the actual parameter. Therefore, the function body and the call to it is identical to that of call by value, but has the effect of call by pointer.

To pass an argument by reference, the function call is similar to that of call by value. In the function declaratory, those parameters, which re to be received by reference must be preceded by the & operator. The reference type formal parameters are accessed in the same way as normal value parameters. However, any modification to them will  also be reflected in the actual parameters.


Share this post