Saved Bookmarks
| 1. |
A. void change(int &);int main(){int x=0;change(x);cout<<"value="<<x;}void change(int & y){y = 40;cout<<"value="<<y;}B. void change(int);int main(){int x=0;change(x);cout<<"value="<<x;}void change(int y){y = 40;cout<<"value="<<y;}1. Predict the output of both programs. 2. Justify your predictions. |
|
Answer» 1. A. Output value = 40 B. output value = 0 2. In the first case (A) the argument x is passed by reference method. So the changes made in the function reflects in main() In the second case (B) the argument x is passed by value method. So the changes made in the function will not reflect in main() |
|