search
Log In
4 votes
4k views

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

in Programming
edited by
4k views
4
26

5 Answers

24 votes
 
Best answer
$x = 2, y = 5$

$y =$ jumble$(5,2)$ //call by value and $y$ will hold return value. After this call $x = 2, \: y = 12$

$x =$ jumble$(12, 2)$ //call by value and $x$ will hold return value. After this call $x = 26, \: y = 12$

$x=26$

edited by
0
Can we tell like this

that "when there is a storage, call by value can work same as call by reference " or

"when there is a storage, call by value can calculate value from other function"
0
please answer this

Can we tell like this

that "when there is a storage, call by value can work same as call by reference " or

"when there is a storage, call by value can calculate value from other function"
0

I think YES because it is returning the value and coming back to main() so it assigns(updates) returned value to the specific variable [for which function is assigned & invoked]

you can try deleting x=jumble(y,x) ,return 0 and any other values to see the effects.

(please correct me if I'm wrong)

0
if return statement not given then value of x y not changed it works just simple call by value
2 votes

Hope this helps :)

0
It means that first we run y  = jumple(y,x) and update the value of Y and then take x = jumple(y,x) and update it and got the final answer. i m little confused that in the jumple func() it written x = 2*x+y;
0 votes

jumble function is just taking 2 arguments say arg1 and arg2. and returning (2*arg1) + arg2

in main function we have below:

y=jumble(5,2);---main called jumble function with arguments 5,2 initially  and result was stored in variable y

here y becomes 12  i.e: (2*10)+2

x remains same which is 2

x=jumble(12, 2);----main again called jumble function with arguments 12,2  and stored in variable x

so x becomes 26   i.e: (2*12)+2

finally x will be printed
output: 26

 

0 votes
1st jumble will return 12 that will be stored in y.

this y will be passed as parameter in 2nd jumble that will return 26 in x.
0 votes
y=jumble(5,2) will return 12 and

x=jumble(12,2) will return 26

so pf(x)-->26

Answer---26
Answer:

Related questions

6 votes
7 answers
1
3.9k views
Consider the following C program: #include <stdio.h> int main() { int arr[]={1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 5}, *ip=arr+4; printf(“%d\n”, ip[1]); return 0; } The number that will be displayed on execution of the program is _______
asked Feb 7, 2019 in Programming Arjun 3.9k views
6 votes
4 answers
2
3.8k views
Consider the following C program: #include <stdio.h> int main() { float sum = 0.0, j=1.0, i=2.0; while (i/j > 0.0625) { j=j+j; sum=sum+i/j; printf("%f\n", sum); } return 0; } The number of times the variable sum will be printed, when the above program is executed, is _________
asked Feb 7, 2019 in Programming Arjun 3.8k views
5 votes
3 answers
3
4.6k views
Consider the following C program: #include <stdio.h> int main() { int a[] = {2, 4, 6, 8, 10}; int i, sum=0, *b=a+4; for (i=0; i<5; i++) sum=sum+(*b-i)-*(b-i); printf("%d\n", sum); return 0; } The output of the above C program is _______
asked Feb 7, 2019 in Programming Arjun 4.6k views
21 votes
10 answers
4
7.8k views
Consider the following C program: #include <stdio.h> int r() { static int num=7; return num--; } int main() { for (r();r();r()) printf(“%d”,r()); return 0; } Which one of the following values will be displayed on execution of the programs? $41$ $52$ $63$ $630$
asked Feb 7, 2019 in Programming Arjun 7.8k views
...