Computer Science, asked by harshitgandotr, 1 year ago

how to appy call by value in simple words?
please give me answer

Answers

Answered by kvnmurty
0
The apply the call by value in a function,  you have to use the formal parameter specification as per call by value.   The language tells you how to specify for call by value or call by reference mechanisms.  You have to follow that way as told by the rule of the language.

It is the default mechanism in a programming language, in general.  You just have to write the variable name (identifier) or expression as the parameter of the function, when calling the function.

=======================================
Suppose you have a function defined as follows.
 
   integer  My_add( integer A,  integer B) 
   begin 
           integer  C =  A + B ;
            //  A = 10;   B = 7;
   end
============
In the main program you call the function by the following procedural (sequential control) statement.

   integer X, Y, Z ;
   X = 5;
   Y = 4 ;
   Z =  My_add ( X, Y) ;
====================
you can also write  :    Z = My_add (5, 4);

Here the formal parameters A and B in the function My_add are call by value parameters.  The parameters X and Y in the main program will not be changed after the addition function is executed.

Thus even the commented statements in the function are executed, the values of X and Y in the main program do not change.

Similar questions