int g (int x, int y) {
switch(x - y) {
case 0:
return x;
case 4:
y = y + 1;
break;
case 7:
x = x - 1;
case 9:
return x*y;
case 3:
y = x + 9;
default:
return y - x;
}
return y;
}
Answers
Answered by
1
I'm assuming the output is required for g(3,0).
So, the value that is put into the switch is (x-y) or (3-0) or 3.
So, it enters case 3:
y=x+9
y=3+9
y=12
x=3
But, now as no break has been added at the end of case 3: so fall through takes place and the control also enters the default: block of switch...case.
So, (y-x) or (12-3) or 9 is returned and then the program ends.
So, the output will be 9
Similar questions