StreakPeaked· Practice

ExamsGATETechnical

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?

  1. If the inputs are x=20, y=10, then the return value is greater than 2²⁰
  2. If the inputs are x=20, y=20, then the return value is greater than 2²⁰
  3. If the inputs are x=2⁰, y=10, then the return value is less than 2¹⁰
  4. If the inputs are x=1⁰, y=20, then the return value is greater than 2²⁰

Correct answer: If the inputs are x=20, y=20, then the return value is greater than 2²⁰

Solution

The function doubles the value of x and adds y in each iteration of the loop, leading to exponential growth. For x=20 and y=20, the number of iterations (20) allows the value of x to increase significantly, resulting in a return value that exceeds 2²⁰.

Related GATE Technical questions

⚔️ Practice GATE Technical free + battle 1v1 →