Multiple choice

Give the output for the following: #include int g=10; void fun(int &x,int y) { x=x-y; y=x*10; cout<<x<<,<<y; } void main() { int g=5; fun(::g,g); }

  1. 0, 0

  2. -5, -50

  3. 10, 50

  4. 5, 50

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The function fun receives global g (value 10) by reference and local g (value 5) by value. x=x-y makes x=10-5=5. Then y=x*10 makes y=5*10=50. Output is '5,50'. The global g is modified to 5, but the local g in main remains unchanged.