ProgrammingHard

char s[] = "a1B2-c"; int n = 0; for (char *p = s; *p; p++) if (isalpha((unsigned char)*p)) n++; printf("%d", n); What is printed?

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

Correct answer: A. 3

isalpha is true only for letters, so in a1B2-c it counts a, B and c: 3. 2 forgets that isalpha accepts uppercase too, and 4 counts the '-' as well.

More C Programming questions

Exams that ask this topic