What is function? Explain call by value and call by reference with example.
Answers
Answered by
8
➡A function is a rule which relates the values of one variable quantity to the values of another variable quantity, and does so in such a way that the value of the second variable quantity is uniquely determined by (i.e. is a function of) the value of the first variable quantity.
⭐CALL BY REFERENCE :⭐
The call by reference method of passing arguments to a function copies the reference of an argument into the formal parameter. Inside the function, the reference is used to access the actual argument used in the call. This means that changes made to the parameter affect the passed argument.
⭐CALL BY VALUE:⭐
The call by value method of passing arguments to a function copies the actual value of an argument into the formal parameter of the function.By default, C programming uses call by value to pass arguments. In general, it means the code within a function cannot alter the arguments used to call the function.
Answered by
2
Function →
• Function or methods are sub programs within the main program which processes the data and often returns a value
Call by reference →
• Call by reference is the process of passing the reference of actual parameters to the formal parameters . Any change made in the formal parameters will be reflected on the actual parameter
Call by value →
• Call by value is the process of passing a copy of actual parameters to the formal parameters . Any change made in the formal parameters does not reflect the actual parameters
Similar questions