Question 7
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
#include <string.h>
int main(void) {
static const char vowels[] = "aeiou";
const char *word = "constant";
int n = 0;
for (const char *p = word; *p; p++)
if (strchr(vowels, *p))
n++;
printf("%d\n", n);
return 0;
}
- A 2 Correct
- B 3
- C 1
- D 8
Correct Answer: Option A
"constant" contains o and a. strchr() takes a const char *, so const data passes straight in. (Careful: strchr(s, '\0') finds the terminator, but the loop never passes '\0'.)
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!