Question 8
Back to Exercise
What is the output of the following C program?
#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!