No one should! In fact, you should prefer const int sum = 1; above #define sum 1 for a number of reasons:
Visibility Based Mechanism:
#define not realm, so there is no way to create a namespace with a limited class. Although constant variables can be limited in classes.
Avoid weird magic numbers with compilation errors:
If you use #define , they are replaced by the pre-processor during pre-compilation. So if you get an error message at compile time, it will be confused because the error message will not refer to the macro name, but the value and it will appear a sudden value, and everyone could spend a lot of time tracking this code .
Easy debugging:
Also for the same reasons stated in # 2, while debugging #define will not give any help.
Thus, to avoid the above situations, const would be a better choice.
Alok Save Jun 08 2018-11-11T00: 00Z
source share