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
jumblearey(which is ) andx(which is ). - Inside
jumble(int x, int y):- The formal parameter
xreceives the value . - The formal parameter
yreceives the value .
- The formal parameter
- The statement
x = 2 * x + y;is executed: - The function returns
x(which is ). - In
main(), this returned value is assigned toy.
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
jumblearey(which is ) andx(which is ). - Inside
jumble(int x, int y):- The formal parameter
xreceives the value . - The formal parameter
yreceives the value .
- The formal parameter
- The statement
x = 2 * x + y;is executed: - The function returns
x(which is ). - In
main(), this returned value is assigned tox.
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.
