GATE / CS ARCHIVE

GATE CSE 2025 SET 2 / QUESTION 63

GATE CSE 2025 Set 2 Q63

Programming in C · Functions & Parameter Passing · Full GATE CSE 2025 Set 2 paper

GATE 2025 Set 2, Q63 2 marks · NAT
Report issue

Functions & Parameter Passing

Question 63, GATE 2025: A C program defines g(n)=n+10 and f(n)=g(n*2). It initializes sum=0 and executes for(n=1;n<3;n++) sum += g(f(n)); then prints sum. What integer is printed?
Tap to enlarge
Answer & solution

Official answer: 46

Resolve the function composition from the innermost call outward. Since g(t)=t+10, f(n)=g(2n)=2n+10. Applying g again gives g(f(n))=f(n)+10=2n+20. The two additions of 10 arise from two separate g calls; the outer one does not double its input.

The loop condition is n<3, so it runs for n=1 and n=2 only. At n=1, f(1)=12 and g(f(1))=22, taking sum from 0 to 22. At n=2, f(2)=14 and g(f(2))=24, taking sum to 46. After incrementing n to 3 the condition fails, and no n=3 term is added. The printed value is 46.

Original paper, page 47 · Answer key