M
Mike Smith
johny said:I have never really understood the difference between
1.) #define NUMBER 1.653
vs.
2.) const double NUMBER = 1.653
I know that the #define is taken care of by the pre-processor and the
compiler is used in the second case but why would one be chosen over the
other.
One book I read suggested that your should prefer the compiler to the
preprocessor, but why does it really matter?
Here's another reason in addition to those already given:
#define MACRO 1.653
const double CONST = 1.653;
double Square(double const *p)
{
return (*p) * (*p);
}
int main()
{
double a = Square(&MACRO); // won't compile
double b = Square(&CONST); // compiles OK
return 0;
}