Question 6
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
static const int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main(void) {
int first_half = 0;
for (int m = 0; m < 6; m++)
first_half += days[m];
printf("%d\n", first_half);
return 0;
}
- A 181 Correct
- B 182
- C 184
- D 180
Correct Answer: Option A
31 + 28 + 31 + 30 + 31 + 30 = 181 (a non-leap year). Reading a const table is unrestricted; only writes are forbidden.
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!