Symbolic Constants
We can define a symbolic constant at the top of the file
#define SPEED_OF_LIGHT 299792458.0
|
Symbolic constants used to avoid burying "magic numbers" in the code
Symbolic constants make the code easier to understand and maintain
#define NAME replacement_text
|
- The compiler's pre-processor will replace all occurrences of
name with replacement_text
- it will not make the replacement if
name is inside quotes ("…" ) or part of another name
Example:
The constants TRUE and FALSE are often used when a condition with logical value is wanted. They can be defined by:
#define TRUE 1
#define FALSE 0
|
|