GateAI
Programming in C

GATE CSE 2016 Set 2 · Q12

NAT1 markEasy

Time

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

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 30

Programming in C

Let us trace the execution of the program step-by-step:

  1. In main(), local variables are initialized as i = 5 and j = 10.

  2. 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).

  3. Inside f():

    • m = m + 5; updates local variable m to 10+5=1510 + 5 = 15.

    • *p = *p + m; updates i to 5+15=205 + 15 = 20.

    • The function returns, and the local copy m is discarded.

  4. Back in main():

    • i has the updated value 20.

    • j remains unchanged as 10.

  5. The expression i + j evaluates to 20+10=3020 + 10 = 30.

Hence, the printed value is 30.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

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

Where do you stand for GATE?

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.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Programming in C in GATE CSE

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 C

More from GATE CSE 2016 Set 2

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2016 Set 2 · Q12 · NAT

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

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.