C
Programming and Technical
Category
Consider the following code:
function modify(y,z)
{
y = y + 1
z = z + 1
return y - z
}
function calculate( )
{
integer a = 12, b = 20, c
c = modify(a, b);
print a
print space
print c
}
Assume that a and b were passed by reference. What will be the output of the function calculate( ) ?
Read Solution (Total 13)
-
- 13 -8
since it is pass by reference the value of an a will be affect the original value.
so it became 13 and 13-21 will be -8 - 10 years agoHelpfull: Yes(13) No(8)
- modify(12,20)
y = 12,z = 20
y = 12+1 = 13
z = 20+1 = 21
c = y-z = 13 - 21 = -8
12_-8 - 10 years agoHelpfull: Yes(7) No(9)
- a=13,c=-8
suppose A address is 100 and the value it contains ia 12,
suppose B address is 200 and the value it contains ia 20,
here calculate function calls modify function through pass by refference so it sends modify(100,200).
modify(y,z) takes modify(100,200) so y address is 100 and z address is 200
so, if any changes occur in y value it reflects the address of 100 as well as z
now y value 13 and z=21 c=-8 .
- 10 years agoHelpfull: Yes(7) No(2)
- c = modify(12,20)
y = 13
z = 21
c = -8
result : 12 -8 - 10 years agoHelpfull: Yes(4) No(1)
- print a statement prints value=13
print a statement prints value=-8
- 10 years agoHelpfull: Yes(3) No(2)
- 12 -8 ais not modified so 12.c is returned from function modify as -8.
- 10 years agoHelpfull: Yes(3) No(0)
- 12 -8 bcz it is called by value not by reference ...
- 9 years agoHelpfull: Yes(2) No(0)
- 12 8, (y+1)-(z+1) = (y-z)
- 10 years agoHelpfull: Yes(0) No(0)
- 12 20 will pass to the function modify then there operations are perform and finaly 8 will print
- 8 years agoHelpfull: Yes(0) No(0)
- -8 will be output
- 8 years agoHelpfull: Yes(0) No(0)
- value of a=12 and value of c=(-8);
because value of a is calculated on the base of local variable has maximum priority than other variables in function calculator()
and function modify() calculate the value of c because the return stored the output in right most variable i.e z which is equal to c that's why c=(-8) - 7 years agoHelpfull: Yes(0) No(0)
- the output is 12 -8
because the value of a remains same in the above program we assigned value of a to variable y
so it s value doesnt change coming to the value of c=y-z=13-21=-8 - 5 years agoHelpfull: Yes(0) No(0)
- a=12,
c=-8 - 5 Months agoHelpfull: Yes(0) No(0)
C Other Question