+ 5
What is the difference between #define and const in C?
" #define " is a preprocessor directive to define macros that can be used through out your code. And you can also define constants with it. On the other hand, " const " is a keyword that is used to declare constants. So, why both?
2 Answers
+ 4
#define is used for exact replacements.
#define ABC 2+2
...
some_variable = ABC*ABC;
printf("%d",some_variable);
...
Output is not 4*4 = 16. It is 2+2*2+2 = 8.
And, 'const' is used only to store a single value.
+ 2
i think its the same.. just whether you prefer to define it or using const