Different between define and const in c | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
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 Réponses
+ 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