ProgrammingModerate

char s[] = "A1b2"; int d = 0; for (int i = 0; s[i]; i++) if (s[i] >= '0' && s[i] <= '9') d++; printf("%d", d); What is printed?

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

Correct answer: B. 2

Only '1' and '2' are digits. The letters A and b are skipped, and the loop stops at the terminator.

More C Programming questions

Exams that ask this topic