Skip to content
Related Articles

Related Articles

Improve Article

GATE | GATE-CS-2016 (Set 2) | Question 22

  • Last Updated : 12 Aug, 2021

The value printed by the following program is




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

Attention reader! Don’t stop learning now.  Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.

Learn all GATE CS concepts with Free Live Classes on our youtube channel.

My Personal Notes arrow_drop_up
Recommended Articles
Page :