ProgrammingModerateAccenture · Cognizant

What is printed?

What is printed?
int a = 0, b = 10;
while (a < b) { a += 3; b -= 2; }
printf("%d %d", a, b);
  1. A. 6 6
  2. B. 3 8
  3. C. 9 4
  4. D. 6 8

Correct answer: A. 6 6

After pass 1: a = 3, b = 8 (3 < 8, continue). After pass 2: a = 6, b = 6, and 6 < 6 is false, so the loop stops. '9 4' runs one extra pass.

More C Programming questions

Exams that ask this topic