Skip to content
GATEiit

GATE CSE 2024 Session 1 Q48: Return value bounds of a loop computing x = x + x + y

Question

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?

Try it: multiple select: one or more correct options

Select one or more options
Select all correct options. No negative marking, no partial marks.
Show answer and explanation

Answer: B, D (official GATE 2024 final answer key)

Concept used: The update x→2x+yx \to 2x + y repeated yy times gives a closed form.

First step: Show x+yx + y doubles each iteration, so the result is 2y(x+y)−y2^y(x + y) - y.

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 2024 Session 1 CS question paper and final answer key, organised by IISc Bangalore. Question paper · Answer key