C++ › Preprocessor & Macros
What is the difference between a macro constant and a constexpr/const constant?
IntermediateAnswer
A #define constant is untyped preprocessor text substitution with no scope, no type checking, and no debug symbol. A const/constexpr constant is a typed, scoped variable known to the compiler and debugger, participating in overload resolution and type safety. Modern C++ strongly prefers constexpr/const over #define for constants.
#define MAX 100 // untyped text
constexpr int Max = 100; // typed, scoped, debuggableReal-world example Replacing #define constants with constexpr gives type safety and lets them appear in the debugger.