Skip to content
GATEiit

GATE CSE 2025 Session 2 Q63: Sum of nested function calls in a loop

Question

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)

Try it: numerical answer: type the value

Numerical answer. No negative marking.
Show answer and explanation

Answer: 46 (official GATE 2025 final answer key)

Concept used: Evaluate the composed functions: g(f(n))=2n+20g(f(n)) = 2n + 20.

First step: The loop runs for n=1n = 1 and n=2n = 2; compute g(f(1))g(f(1)) and g(f(2))g(f(2)).

Full step-by-step solution

Detailed working, common mistakes and linked mock tests will be available with a free GATEiit account. Log-in is coming soon.

Share this question

WhatsAppDownload image

Source: official GATE 2025 Session 2 CS question paper and final answer key, organised by IIT Roorkee. Question paper · Answer key