GateAI
Programming in C

GATE CSE 2024 Set 1 · Q48

MSQ2 marksMedium

Time

Consider the following C function definition.int f(int x, int y) { for (int i=0; i<y; i++) { x=x+x+y; } return x; }Which of the following statements is/are TRUE about the above function?

Select all that applyOne or more correct

Pick every correct option

Solution

Step-by-step verified solution

Official answer: B) If the inputs are x=20, y=20, then the return value is greater than 220; D) If the inputs are x=10, y=20, then the return value is greater than 220

Programming in C

In each iteration of the loop, the value of xx is updated as:

xk=2xk−1+yx_{k} = 2x_{k-1} + y

Adding yy to both sides gives a geometric progression:

xk+y=2(xk−1+y)x_{k} + y = 2(x_{k-1} + y)

After yy iterations (since the loop runs yy times):

xy+y=2y(x0+y)  ⟹  xy=2y(x0+y)−yx_{y} + y = 2^y (x_0 + y) \implies x_{y} = 2^y (x_0 + y) - y

Let us evaluate each option using this recurrence relation:

  • (A) and (C) with x=20,y=10x = 20, y = 10:

    return value=210(20+10)−10=30×1024−10=30710\text{return value} = 2^{10}(20 + 10) - 10 = 30 \times 1024 - 10 = 30710

    Since 30710<220=104857630710 < 2^{20} = 1048576, statement (A) is FALSE. Since 30710>210=102430710 > 2^{10} = 1024, statement (C) is FALSE.

  • (B) with x=20,y=20x = 20, y = 20:

    return value=220(20+20)−20=40×220−20\text{return value} = 2^{20}(20 + 20) - 20 = 40 \times 2^{20} - 20

    Since 40×220−20>22040 \times 2^{20} - 20 > 2^{20}, statement (B) is TRUE.

  • (D) with x=10,y=20x = 10, y = 20:

    return value=220(10+20)−20=30×220−20\text{return value} = 2^{20}(10 + 20) - 20 = 30 \times 2^{20} - 20

    Since 30×220−20>22030 \times 2^{20} - 20 > 2^{20}, statement (D) is TRUE.

Hence, the correct options are B and D.

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 Q48 of the GATE CSE 2024 Set 1 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. This is the only 2-mark MSQ among them, and GATE CSE 2024 Set 1 has 3.

How GATE tests Programming in C

More from GATE CSE 2024 Set 1

Share this solution

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

GateAI solution cardGATE CSE 2024 Set 1 · Q48 · MSQ

Consider the following C function definition. int f(int x, int y) { for (int i=0; i Which of the following statements is/are TRUE about the above function?

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.