Possible Duplicate:
“static const” vs “#define” in c
When I do this :
#define WEEKDAYS 7
and that :
const int WEEKDAYS = 7;
Any difference between them ? seems that both do the same thing - sets a constant value for future usage within the code .
#define WEEKDAYS 7
void f() {
int WEEKDAYS = 3; // error
}
const int WEEKDAYS_CONST = 7;
void g() {
int WEEKDAYS_CONST = 3; // okay: local scope for WEEKDAYS_CONST
}
#define WEEKDAYS 7
Replaces all occurrence of the word WEEKDAYS
in your source file with the digit 7.
const int WEEKDAYS = 7;
Defines an actual constant represented by 7 that you can access in your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With