ProgrammingModerate

char s[] = "aXbXc"; int x = 0; for (int i = 0; s[i]; i++) x += s[i] == 'X'; printf("%d", x); What is printed?

  1. A. 3
  2. B. 1
  3. C. 4
  4. D. 2

Correct answer: D. 2

The boolean comparison adds 1 for each X, and there are two X characters.

More C Programming questions

Exams that ask this topic