The Gateway to Computer Science Excellence
+2 votes
2.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 by Veteran (424k points)
edited by | 2.4k views
+3
26

4 Answers

+16 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$
by Veteran (60.5k points)
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 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

 

by (119 points)
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.
by (421 points)
0 votes
y=jumble(5,2) will return 12 and

x=jumble(12,2) will return 26

so pf(x)-->26

Answer---26
by (259 points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,648 questions
56,429 answers
195,216 comments
99,945 users