GATE 2024 CS (CS1) – Question 48
Consider the C function:
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?
Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: (A) If the inputs are x=20, y=10, then the return value is greater than $2^{20}$; (B) If the inputs are x=20, y=20, then the return value is greater than $2^{20}$; (D) If the inputs are x=10, y=20, then the return value is greater than $2^{20}$
Explanation
Each iteration roughly doubles x and adds y, so the result is about x·2^y. For (20,10): ≥20·1024 > 2^14 and with additions exceeds 2^20; (20,20) and (10,20) clearly exceed 2^20. C is false.