#define MY_INT VS const int MY_INT
13,145
Solution 1
#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
}
Solution 2
#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.
Comments
-
JAN almost 2 years
Possible Duplicate:
“static const” vs “#define” in cWhen 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 .