GATE 2019 CS – Question 28
Consider the following C program:
#include <stdio.h>
int jumble(int x, int y){
x=2*x+y;
return x;
}
int main(){
int x=2, y=5;
y=jumble(y,x);
x=jumble(y,x);
printf("%d \n", x);
return 0;
}The value printed by the program is ________.
Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: 26
Explanation
C passes arguments **by value**, so changes to `x` inside `jumble` do not affect the caller.
- `y = jumble(y, x)` with `y=5`, `x=2`: inside, `x = 2*5 + 2 = 12`, so `y = 12`.
- `x = jumble(y, x)` with `y=12`, `x=2`: inside, `x = 2*12 + 2 = 26`, so `x = 26`.
The program prints **26**.