#defining constants in C++

后端 未结 7 986
轮回少年
轮回少年 2021-02-01 03:50

In various C code, I see constants defined like this:

#define T 100

Whereas in C++ examples, it is almost always:

const int T =         


        
相关标签:
7条回答
  • 2021-02-01 04:32

    One other cool point is that global integral constants could be optimized out by the compiler so that they do not take up any space (i.e., memory). Therefore, they can be treated as literal constants when they are used and be as optimal as #define based constants, without all of the pre-processor issues.

    0 讨论(0)
提交回复
热议问题