Multiple choice

What is the output of the following program? #include<iostream.h> void x(int a,int &b) { a=a+b; a=a-b; b=b-a; } void main() { int a=4,b=10; x(a,b); cout<<a<<b;
}

  1. 4, 10

  2. 10, 4

  3. 4, 4

  4. 4, 6

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

The function x uses pass-by-reference for b. Inside x: a becomes 4+10=14, then a becomes 14-10=4, then b becomes 10-4=6. The original a remains 4, and b is updated to 6.