Consider the following C program: #include int main() { int a = 6; int b = 0; while(a Which one of the following statements is CORRECT?
Topic-wise GATE CS PYQs with verified steps
GATE CSE 2024 Set 1 · Q18
Time
#include <stdio.h>
int main() {
int a = 6;
int b = 0;
while(a < 10) {
a = a / 12 + 1;
a += b;
}
printf("%d", a);
return 0;
}Which one of the following statements is CORRECT?Select one answerSingle correct
Solution
Official answer: C) The program gets stuck in an infinite loop
Programming in CLet us trace the execution of the program step by step:
Initial values of variables:
a = 6
b = 0
Iteration 1:
Check condition: a < 10 , which evaluates to true.
a = a / 12 + 1: Since a is an integer, integer division evaluates to . Thus, .
a += b: .
Iteration 2:
Check condition: a < 10 , which evaluates to true.
a = a / 12 + 1: , so .
a += b: .
For all subsequent iterations, a remains , and the condition a < 10 will always be true. Therefore, the loop will never terminate, resulting in an infinite loop.
Thus, statement (C) is correct.
Try the question first, then check your work.
Examiner trap
Trace the integer division a / 12 when a is less than 12.
This Programming in C previous year question is Q18 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. 20 of them are 1-mark MCQs like this one, 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.