LearnFrenzy
Sign in Take a free test

Control Instructions · Predict the Output · Question 8

Counting vowels with grouped case labels Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 8 Back to Exercise

What is the output of the following C program?

main.c
#include <stdio.h>

int main(void) {
    const char *s = "Apple pie";
    int vowels = 0;
    for (const char *p = s; *p; p++) {
        switch (*p) {
        case 'a': case 'e': case 'i': case 'o': case 'u':
        case 'A': case 'E': case 'I': case 'O': case 'U':
            vowels++;
            break;
        default:
            break;
        }
    }
    printf("%d\n", vowels);
    return 0;
}
  • A 4 Correct
  • B 3
  • C 5
  • D 2
Correct Answer: Option A

All ten labels share one action. "Apple pie" contains A, e, i, e – four vowels; the capital A counts because uppercase labels are listed too.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links