GATE | GATE-CS-2016 (Set 2) | Question 22
The value printed by the following program is
C
void f( int * p, int m)
{
m = m + 5;
*p = *p + m;
return ;
}
void main()
{
int i=5, j=10;
f(&i, j);
printf (\"%d\", i+j);
}
|
(A)
10
(B)
20
(C)
30
(D)
40
Answer: (C)
Explanation:
#include\"stdio.h\"
void f(int* p, int m)
{
m = m + 5;
*p = *p + m;
return;
}
int main()
{
int i=5, j=10;
f(&i, j);
printf(\"%d\", i+j);
}
For i, address is passed. For j, value is passed. So in function f, p will contain address of i and m will contain value 10. Ist statement of f() will change m to 15. Then 15 will be added to value at address p. It will make i = 5+15 = 20. j will remain 10. print statement will print 20+10 = 30. So answer is (C).
Quiz of this Question
Please comment below if you find anything wrong in the above post
Last Updated :
12 Aug, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...