LearnFrenzy
Sign in Take a free test

C Const · Predict the Output · Question 3

#define TOTAL 10 + 5 vs enum – output Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 3 Back to Exercise

What is the output of the following C program?

main.c
#include <stdio.h>

#define TOTAL 10 + 5
enum { TOTAL_E = 10 + 5 };

int main(void) {
    printf("%d %d\n", TOTAL * 2, TOTAL_E * 2);
    return 0;
}
  • A 20 30 Correct
  • B 30 30
  • C 30 20
  • D 20 20
Correct Answer: Option A

TOTAL * 2 becomes 10 + 5 * 2 = 20. The enum constant is evaluated once as a value (15), so TOTAL_E * 2 is 30.

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