+1 vote
in Class 12 by kratos

How is call-by-value method of function invoking different from call-by-reference method? Give appropriate examples supporting your answer.

1 Answer

+3 votes
by kratos
 
Best answer

| Call By Value | Call by reference |
| 1. In call by value method, the called function creates its own copies of the original values send to it. | 1. In call by reference method, the called function accesses ad works with the original values using their references. |
| 2. The changes done in the function in formal parameter are not reflected back in the calling environment. | 2. The changes done in the function are reflected back in the calling environment. |
| 3. It does not use the ‘&’ sign | 3. It use ‘&’ sign as the reference operator. |
| Example:#include <iostream.h>void change(int x, int y) {x = 10; /change the value of x /y = 20; /change the value of y /} void change(int x, int y);void main (){// local variable declaration:int a = 100;int b = 200;cout<<"Before value of a "<void change(int x, int y) { x = 10; /change the value of x /y = 20; /change the value of y /}void change(int x, int y);void main () {// local variable declaration:int a = 100;int b = 200;cout<<"Before value of a "<<a <<end1;change(&a, &b);cout<<"After value of a "<<a<<end1;cout<<"After value of b "<<b<<end1;} |

...