Possible duplicate:"static const" vs "#define" in c
When I do this:
#define WEEKDAYS 7
So what:
const int WEEKDAYS = 7;
Any difference between the two? it seems that both do the same thing - sets a constant value for future use in 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 }
Replaces all occurrences of a word WEEKDAYSin the source file with the number 7.
WEEKDAYS
Defines the actual constant represented by 7, which you can get in your code.