Hello Marc Prager,
Some description from the website:
#define is a preprocessor directive. Things defined by #define are replaced by the preprocessor before compilation begins.
const variables are actual variables like other normal variable.
The big advantage of const over #define is type checking. We can also have pointers to const variables, we can pass them around, typecast them and any other thing that can be done with a normal variable. One disadvantage that one could think of is extra space for variable which is immaterial due to optimizations done by compilers.
In general const is a better option if we have a choice. There are situations when #define cannot be replaced by const. For example, #define can take parameters (See this for example). #define can also be used to replace some text in a program with another text.
A #define is used as immediate constant or as a macro. Where as the constant is a variable whose value can not change.
Pointer can be declared to a constant, but not for #define.
#define can not define externally, and there is no way to use it for availability to the linker. Where as the constant can be global .
Wish it helps you!
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------