0
Different between define and const in c
What different between define and const in c programming Where is usage of its
2 Answers
+ 5
Rahman Rezaie
constĀ and #defineĀ both areĀ usedĀ for handleĀ constantsĀ in sourceĀ code, but they fewĀ differences. #defineĀ isĀ usedtoĀ defineĀ some values with a name (string), thisĀ definedĀ string is known as MacroĀ definitionĀ inĀ C, C++ whileĀ constis a keyword orĀ usedĀ to makeĀ theĀ value of an identifier (that isĀ constant) constant.
source:
https://www.includehelp.com/cpp-tutorial/difference-between-const-and-define.aspx
I hope I was helpful
+ 1
>>Constants are fixed value wich they are stored in memory .(memory allocation)
Before the compiler executes the code the preprocessor affect (send)the value when it reaches the constant name.
>>eg:
Int main(){
const int number= 3;
Printf("%d",number);//3
This constant is only accessible in the main function.
>>the define predective processor does not store the value in the the memory,but it search and insert(replace )the value.
>>eg:#define max 50
Int main(){
Int array[max]; //50.
The max value is accessible in all the file with all the functions.
Hope it is clear