Skip to content
Official PYQ · 2019

GATE CS 2019 Q18 — Programming in C

Explain with AI

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 ______________.

View worked solution

Answer: 26

To find the value printed by the program, let us trace the execution step-by-step:

1. Initialization in main()

Initially, we have:
x = 2, y = 5

2. First Function Call: y = jumble(y, x);

  • The actual arguments passed to jumble are y (which is 55) and x (which is 22).
  • Inside jumble(int x, int y):
    • The formal parameter x receives the value 55.
    • The formal parameter y receives the value 22.
  • The statement x = 2 * x + y; is executed: x=2×5+2=12x = 2 \times 5 + 2 = 12
  • The function returns x (which is 1212).
  • In main(), this returned value is assigned to y.

At this point, the variables in main() are:
x = 2, y = 12

3. Second Function Call: x = jumble(y, x);

  • The actual arguments passed to jumble are y (which is 1212) and x (which is 22).
  • Inside jumble(int x, int y):
    • The formal parameter x receives the value 1212.
    • The formal parameter y receives the value 22.
  • The statement x = 2 * x + y; is executed: x=2×12+2=26x = 2 \times 12 + 2 = 26
  • The function returns x (which is 2626).
  • In main(), this returned value is assigned to x.

At this point, the variables in main() are:
x = 26, y = 12

4. Output

The statement printf("%d \n", x); prints the value of x, which is 26.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Programming in C questions