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?
Answer
(C)
Explanation
Both operands of a / 12 are integers, so the division truncates. Starting from a = 6, the first pass gives \(6/12 = 0\), so a becomes \(0 + 1 = 1\), and a += b adds 0.
On every later pass a is 1: the test \(1 < 10\) holds, \(1/12 = 0\), and a is set to 1 again. Since b stays 0, nothing ever raises a to 10, so the condition never fails, the loop never exits and printf is never reached.
Options A, B and D all assume that the loop ends and something is printed.
Answer: C