Different between define and const in c | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Different between define and const in c

What different between define and const in c programming Where is usage of its

19th May 2019, 5:24 PM
Rahman Rezaie šŸ‡¦šŸ‡«
Rahman Rezaie šŸ‡¦šŸ‡« - avatar
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
19th May 2019, 5:48 PM
Alessio Benvenuti
Alessio Benvenuti - avatar
+ 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
12th May 2020, 3:32 AM
Amal Gil
Amal Gil - avatar