C
Programming and Technical
Programming
Output
Consider the following code:
function modify(a,b)
{
integer c, d = 2
c = a*d + b
return c
}
function calculate( )
{
integer a = 5, b = 20, c
integer d = 10
c = modify(a, b);
c = c + d
print c
}
Assume that a and b were passed by value. What will be the output of the function calculate( ) ?
Read Solution (Total 18)
-
- at first it goes to function c = modify(a,b);
passing a=5 and b=20;
c=a*d+b; //where as d is a local variable which is located in modify function.
c=5*2+20;
c=30
and it returns to caluclate() function
and c=c+d;//here d is declared as d=10;
c=30+10;
c=40;
- 10 years agoHelpfull: Yes(21) No(0)
- 40
the function follows the value in the given value in respective function - 10 years agoHelpfull: Yes(1) No(0)
- In claculate function there is another function i.e modify(a,b).....so it goes to modify( ) i.e....c=a*d+b;
c=5*2+20=30
c=20..it returns c value
here again c=c+d..i.e
c=30+10=40
therefore ans ..is 40... - 10 years agoHelpfull: Yes(1) No(0)
- modify(5,20)
c = 5*2+20 = 30
c = 30 + 10
c = 40 - 10 years agoHelpfull: Yes(1) No(0)
- Since c is declared inside the function. It's scope will end at the function exists so the value of c would become zero ans is 10
- 10 years agoHelpfull: Yes(1) No(1)
- output of function calculate will be 40
- 10 years agoHelpfull: Yes(1) No(0)
- statement return c returns value 30. then c=30 and d=10. final output of funcction calculate() is 40
- 10 years agoHelpfull: Yes(1) No(0)
- 40 is the correct answer
- 10 years agoHelpfull: Yes(1) No(0)
- C value=40
- 10 years agoHelpfull: Yes(0) No(0)
- c=40
bcz when function modify is called the value of c=5*2+20=30 and its value is returned to calling function in main.then we calculate c by takng d=10 bcz in main the value of d=10 due to local scope and calculate c=30+10=40 - 10 years agoHelpfull: Yes(0) No(0)
- 40 i guess
- 10 years agoHelpfull: Yes(0) No(0)
- c=modify(5,20)
modify(5,10)
{
- 10 years agoHelpfull: Yes(0) No(0)
- ans will be 40
- 10 years agoHelpfull: Yes(0) No(0)
- c=40
when a=5 and b=20 pass through modify function,c will get calculated as (5*2)+20
and c=30 is returned
which is added with the value of local function calculate c=30+10
i.e. c=40 - 10 years agoHelpfull: Yes(0) No(0)
- value of c 40
- 10 years agoHelpfull: Yes(0) No(0)
- Ans will be 40
- 10 years agoHelpfull: Yes(0) No(0)
- ans is 40
- 10 years agoHelpfull: Yes(0) No(0)
- ans is 40
- 10 years agoHelpfull: Yes(0) No(0)
C Other Question