LearnFrenzy
Sign in Take a free test

C Const · const MCQ · Question 5

#define vs const in C – the key difference Answer, explanation & discussion

  • MCQ
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 5 Back to Exercise

Which statement about #define PI 3.14159 versus const double PI = 3.14159; is true?

  • A Both are typed variables
  • B The macro is untyped text replaced by the preprocessor and ignores scope; the const is a typed, scoped object Correct
  • C The macro uses memory at run time
  • D const is replaced by the preprocessor
Correct Answer: Option B

The preprocessor substitutes the macro's text before compilation, so it has no type, no address and no scope. The const has a type the compiler checks, obeys block scope and is visible in a debugger.

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