The GATE Grind

GATE 2016 CS (CS2) – Question 22

Programming and Data Structures · Programming in C · 1 mark · Numerical answer

What does this C program print?

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);
}

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: 30.0 to 30.0

Explanation

Parameter m is a local copy of j and changes from 10 to 15. Pointer p refers to i, so i becomes 5+15=20. The caller’s j stays 10 because it was passed by value. Thus printf outputs i+j=30.

More Programming in C questions

All Programming in C questions →