Question 9
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
static const char *const colors[] = {"red", "green", "blue"};
int main(void) {
printf("%s %c %zu\n", colors[1], colors[2][0], sizeof colors / sizeof colors[0]);
return 0;
}
- A green b 3 Correct
- B green b 13
- C red g 3
- D green blue 3
Correct Answer: Option A
colors[1] is "green", colors[2][0] is the first character of "blue", and the array holds 3 pointers. Both the strings and the pointers are read-only, which is ideal for fixed tables.
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!