Why would someone use #define to define constants?

前端 未结 9 1702
星月不相逢
星月不相逢 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

    const int is just an int that can't change. #define is a directive to the C preprocessor, which is much more than just for defining constants.

    See here for more details: http://en.wikipedia.org/wiki/C_preprocessor

提交回复
热议问题