Constants and the C Preprocessor
Sometimes you need to use a constant in a program. For example, you could give the circumference of a circle as this:
circumference = 3.14159 * diameter;
Here, the constant 3.14159 represents the world-famous constant pi (ρ). To use a constant, just type in the actual value, as in the example. However, there are good reasons to use a symbolic constant instead. That is, you could use a statement like the following and have the computer substitute in the actual value later:
circumference = pi * diameter;
Why is it better to use a symbolic constant? First, a name tells you more than a number does. Compare these two statements:
owed = 0.015 * housevalue; owed = taxrate * housevalue;
If you read through a long ...
Get C Primer Plus®, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.