Which one is better to use among the below statements in C?
static const int var = 5;
or
#define var 5
o
The difference between static const
and #define
is that the former uses the memory and the later does not use the memory for storage. Secondly, you cannot pass the address of an #define
whereas you can pass the address of a static const
. Actually it is depending on what circumstance we are under, we need to select one among these two. Both are at their best under different circumstances. Please don't assume that one is better than the other... :-)
If that would have been the case, Dennis Ritchie would have kept the best one alone... hahaha... :-)