0
Different between define and const in c
What different between define and const in c programming Where is usage of its
2 Respostas
+ 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