LearnFrenzy
Sign in Take a free test

C Const · Predict the Output · Question 6

Summing part of a static const table – output Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 6 Back to Exercise

What is the output of the following C program?

main.c
#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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links