Exams › GATE › Technical
Consider the following C program:
#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?
- The program prints 9 as output
- The program prints 10 as output
- The program gets stuck in an infinite loop
- The program prints 6 as output
Correct answer: The program gets stuck in an infinite loop
Solution
The program enters an infinite loop because the condition 'a < 10' remains true indefinitely. The value of 'a' is updated in such a way that it never reaches or exceeds 10, causing the loop to continue without termination.
Related GATE Technical questions
⚔️ Practice GATE Technical free + battle 1v1 →