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); }
Topic-wise GATE CS PYQs with verified steps
GATE CSE 2016 Set 2 · Q12
Time
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);
}Your answerNumerical answer
Solution
Official answer: 30
Programming in CLet us trace the execution of the program step-by-step:
In main(), local variables are initialized as i = 5 and j = 10.
The function f(&i, j) is called:
p receives the address of i (&i), so *p directly modifies i in main() (pass-by-reference / pointer).
m receives the value 10 (pass-by-value).
Inside f():
m = m + 5; updates local variable m to .
*p = *p + m; updates i to .
The function returns, and the local copy m is discarded.
Back in main():
i has the updated value 20.
j remains unchanged as 10.
The expression i + j evaluates to .
Hence, the printed value is 30.
Try the question first, then check your work.
Examiner trap
Notice that i is passed by address (pointer) while j is passed by value.
This Programming in C previous year question is Q12 of the GATE CSE 2016 Set 2 paper. Find more GATE CSE PYQs on Programming in C in Programming and Data Structures, or browse all GATE CSE PYQs.
Free diagnostic
Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Programming in C PYQs now with no account.
An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.
Programming in C has 74 GATE CSE PYQs across 25 papers from 2011 to 2026. 16 of them are 1-mark NAT questions like this one, and GATE CSE 2016 Set 2 has 3.
How GATE tests Programming in CIndependent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.