ProgrammingModerateTCS NQT · Accenture

What is printed?

What is printed?
int x = 0;
if (x == 1);
    x += 5;
printf("%d", x);
  1. A. 1
  2. B. 5
  3. C. 6
  4. D. 0

Correct answer: B. 5

The semicolon right after the if is an empty statement, which is all the if controls. The indented x += 5 is an ordinary statement that always runs. The indentation misleads; C ignores it.

More C Programming questions

Exams that ask this topic