Which one is better to use among the below statements in C?
static const int var = 5;
or
#define var 5
o
I am not sure if I am right but in my opinion calling #define
d value is much faster than calling any other normally declared variable (or const value).
It's because when program is running and it needs to use some normally declared variable it needs to jump to exact place in memory to get that variable.
In opposite when it use #define
d value, the program don't need to jump to any allocated memory, it just takes the value. If #define myValue 7
and the program calling myValue
, it behaves exactly the same as when it just calls 7
.