GateAI
Programming in C

GATE CSE 2025 Set 2 · Q63

NAT2 marksEasy

Time

Consider the following C program:#include <stdio.h> int g(int n) { return (n+10); } int f(int n) { return g(n*2); } int main() { int sum, n; sum=0; for (n=1; n<3; n++) sum += g(f(n)); printf ("%d", sum); return 0; }The output of the given C program is ________. (Answer in integer)

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 46

Programming in C

Let us trace the functions step-by-step:

  1. The function g(n)g(n) returns n+10n + 10.

  2. The function f(n)f(n) calls g(2n)g(2n), which evaluates to:

    f(n)=2n+10f(n) = 2n + 10
  3. The expression $g(f(n))$ evaluates to:

    g(f(n))=f(n)+10=(2n+10)+10=2n+20g(f(n)) = f(n) + 10 = (2n + 10) + 10 = 2n + 20

Now, trace the for loop in main() with initial sum = 0:

  • Iteration 1 (n=1n = 1):

    g(f(1))=2(1)+20=22g(f(1)) = 2(1) + 20 = 22
    sum=0+22=22\text{sum} = 0 + 22 = 22
  • Iteration 2 (n=2n = 2):

    g(f(2))=2(2)+20=24g(f(2)) = 2(2) + 20 = 24
    sum=22+24=46\text{sum} = 22 + 24 = 46
  • Iteration 3 (n=3n = 3): The condition n<3n < 3 evaluates to false, and the loop terminates.

printf("%d", sum) prints 46.

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 Q63 of the GATE CSE 2025 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. 17 of them are 2-mark NAT questions like this one, and GATE CSE 2025 Set 2 has 4.

How GATE tests Programming in C

More from GATE CSE 2025 Set 2

Share this solution

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

GateAI solution cardGATE CSE 2025 Set 2 · Q63 · NAT

Consider the following C program: #include int g(int n) { return (n+10); } int f(int n) { return g(n*2); } int main() { int sum, n; sum=0; for (n=1; n The output of the given C program is … (Answer in integer)

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.