GateAI
Programming in C

GATE CSE 2019 · Q18

NAT1 markEasy

Time

Consider the following C program:#include <stdio.h> int jumble(int x, int y){ x=2*x+y; return x; } int main(){ int x=2, y=5; y=jumble(y,x); x=jumble(y,x); printf("%d ", x); return 0; }The value printed by the program is _______.

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 26

Programming in C

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

  1. Initial state in main:

    x=2,y=5x = 2,\quad y = 5
  2. First function call: y = jumble(y, x); which is jumble(5, 2):

    • In jumble(int x, int y): local x = 5, local y = 2

    • x = 2 * 5 + 2 = 12

    • Returns 1212.

    • In main: y is updated to 1212, while x remains 22.

  3. Second function call: x = jumble(y, x); which is jumble(12, 2):

    • In jumble(int x, int y): local x = 12, local y = 2

    • x = 2 * 12 + 2 = 26

    • Returns 2626.

    • In main: x is updated to 2626.

  4. `printf("%d

", x); prints the value of x`, which is 26.

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 Q18 of the GATE CSE 2019 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 2019 has 3.

How GATE tests Programming in C

More from GATE CSE 2019

Share this solution

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

GateAI solution cardGATE CSE 2019 · Q18 · NAT

Consider the following C program: #include int jumble(int x, int y){ x=2*x+y; return x; } int main(){ int x=2, y=5; y=jumble(y,x); x=jumble(y,x); printf("%d ", x); return 0; } The value printed by the program is …

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.