how to appy call by value in simple words?
please give me answer
Answers
Answered by
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.
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
Social Sciences,
8 months ago
Computer Science,
8 months ago
Math,
8 months ago
Computer Science,
1 year ago
English,
1 year ago
Chemistry,
1 year ago