GATE 2024 CS (CS1) – Question 18
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?
Practise this question in The GATE Grind →
Show answer and explanation
Correct answer: (C) The program gets stuck in an infinite loop
Explanation
With a<10, a/12 is 0 so a becomes 1, then a+=0 keeps a=1. a stays below 10 forever, so the loop never terminates.