Multiple choice

What is the output of the following program? #include<iostream.h> void fun(int &a,int &b) { a=a*b; b=b-a; a=a-b; } void main() { int a=6,b=30; fun(a,b); cout<<a<< , <<b; }

  1. -330,150

  2. 330, -150

  3. -150, -330

  4. 6, 30

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

Tracing the function: initially a=6, b=30. After a=a*b: a=180. After b=b-a: b=30-180=-150. After a=a-b: a=180-(-150)=330. Since parameters are passed by reference, main's variables are modified. The final output is '330, -150'. The function effectively swaps and scales values through arithmetic operations.