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);- A. 5 5
- B. 4 9
- C. 5 9
- 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
- Which of these functions return a pointer that is still valid to read after the function returns? c char f1(void) { char s[] = "hi"…
- Assume 32-bit unsigned int. What is printed? c unsigned int x = 65536; printf("%u %u", x x, x (x - 1) / 2);
- What is printed? c int i = 0; while (i++ < 5); printf("%d", i);
- What is printed? c #define LEVEL 2 #if LEVEL > 1 #define MSG "high" #elif LEVEL > 0 #define MSG "low" #endif #undef LEVEL #ifndef LEVEL…
- What is printed? c struct E { char name[8]; int age; }; struct E t[] = {{"Asha", 31}, {"Bilal", 27}, {"Chen", 45}, {"Dev", 22}}; struct E…
- What is printed? c int f(int a, int n) { if (n == 1) return a[0]; int m = f(a + 1, n - 1); return a[0] > m ? a[0] - m : m - a[0]; } int…