Why would someone use #define to define constants?

前端 未结 9 1718
星月不相逢
星月不相逢 2020-11-27 04:02

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

9条回答
  •  伪装坚强ぢ
    2020-11-27 04:27

    Always try to use "const int", rather than #define.

    Use #define, only when your preprocessor code might be read by another tool, and it's easier for it to go with the preprocessor, rather than to parse the language.

    Also it's the only way to define something to be checked later by #if/#else/#endif

提交回复
热议问题