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 follows:

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 such as 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 the following two statements:

owed = 0.015 * housevalue;
owed = taxrate * housevalue;

If you read ...

Get C Primer Plus, Fourth 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.