ProgrammingHardAccenture · Capgemini

What is printed?

What is printed?
const char *s = "education";
int v = 0, o = 0;
for (; *s; s++)
    switch (*s) {
        case 'a': case 'e': case 'i':
        case 'o': case 'u': v++;
        default: o++;
    }
printf("%d %d", v, o);
  1. A. 5 5
  2. B. 4 9
  3. C. 5 9
  4. D. 5 4

Correct answer: C. 5 9

All five vowels appear once, so v = 5. There is no break after v++, so every vowel falls through into default as well: o counts all 9 letters, not just the 4 consonants.

More C Programming questions

Exams that ask this topic