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
GATE CSE 2024 Set 1 · Q48
Time
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
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 CIn each iteration of the loop, the value of is updated as:
Adding to both sides gives a geometric progression:
After iterations (since the loop runs times):
Let us evaluate each option using this recurrence relation:
(A) and (C) with :
Since , statement (A) is FALSE. Since , statement (C) is FALSE.
(B) with :
Since , statement (B) is TRUE.
(D) with :
Since , statement (D) is TRUE.
Hence, the correct options are B and D.
Try the question first, then check your work.
Examiner trap
Set up a recurrence relation for in each iteration: , and solve it as .
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
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.
An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.
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 CIndependent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.