Possible Duplicate:
“static const” vs “#define” in c
I am going through the K&R book and this question came up. How to best decide whether something should be its own variable or be defined as a symbolic constant?
Suppose we’re dealing with const int myNumber = 12; , which also can be #define MY_NUMBER 12 is there a rule of thumb one should follow when deciding which whether a variable needs to be created or symbolic constant used?
If you’re hard-coding a constant like “2” … then it’s a candidate for symbolic parameter.
ADDENDUM:
You changed the question 🙂
A: “Magic numbers” are bad. Use “#define SOME_MEANINGFUL_NAME 2” in preference to “2”.
A: If you’re using C++ or C#, then you should probably use “const” in favor of “#define”.