GateAI
Programming in C

GATE CSE 2024 Set 2 · Q13

MCQ1 markEasy

Time

Consider the following C program. Assume parameters to a function are evaluated from right to left.#include <stdio.h> int g(int p) { printf("%d", p); return p; } int h(int q) { printf("%d", q); return q; } void f(int x, int y) { g(x); h(y); } int main() { f(g(10),h(20)); }Which one of the following options is the CORRECT output of the above C program?

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: A) 20101020

Programming in C

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

  1. Evaluation of arguments in main(): The function call is f(g(10), h(20)). Since parameters are evaluated from right to left:

    • First, h(20) is called:

      • It executes printf("%d", 20); which prints 20.

      • It returns 20, so the second argument y=20y = 20.

      • *Current output:* 20

    • Next, g(10) is called:

      • It executes printf("%d", 10); which prints 10.

      • It returns 10, so the first argument x=10x = 10.

      • *Current output:* 2010

  2. Execution inside f(10, 20):

    • g(x) is executed with x=10x = 10:

      • It executes printf("%d", 10); which prints 10.

      • *Current output:* 201010

    • h(y) is executed with y=20y = 20:

      • It executes printf("%d", 20); which prints 20.

      • *Current output:* 20101020

Thus, the final output printed on the screen is 20101020, which corresponds to option (A).

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 Q13 of the GATE CSE 2024 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. 20 of them are 1-mark MCQs like this one, and GATE CSE 2024 Set 2 has 4.

How GATE tests Programming in C

More from GATE CSE 2024 Set 2

Share this solution

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

GateAI solution cardGATE CSE 2024 Set 2 · Q13 · MCQ

Consider the following C program. Assume parameters to a function are evaluated from right to left. #include int g(int p) { printf("%d", p); return p; } int h(int q) { printf("%d", q); return q; } void f(int x, int y) { g(x); h(y); } int main() { f(g(10),h(20)); } Which one of the following options is the CORRECT output of the above C program?

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.