It\'s simple question but why would someone use #define to define constants?
What\'s the difference between
#define sum 1 and const int su
From Introduction to programming with C++ which was written by Daniel Liang stated that:
When you define a constant using
#definedirective, the constant is not stored in memory.The constant will be replaced with a value by compiler. When you declare constant usingconstkeyword, the constant is stored in memory just like variable.
If constant need to be used in multiple programs, use #define to define it in header file so it can be included in other program. If constant used only in one program, using const to declare is more efficient.