Advantage and disadvantages of #define vs. constants? [duplicate]

As 0A0D mentioned, there are #defines, enums, and const variables. It’s worth noting that const-qualified variables are not considered to be compile-time constants in C and therefore can’t be used in some circumstances (e.g. when declaring the size of an array).

enum constants are compile-time constants, however. For integral values, IMO it’s usually better to prefer enums over const variables over #define.

Leave a Comment