E.3 #define
Preprocessing Directive: Symbolic Constants
The #define
preprocessing directive creates symbolic constants—constants represented as symbols—and macros—operations defined as symbols. The #define
preprocessing directive format is
#define identifier replacement-text
When this line appears in a file, all subsequent occurrences (except those inside a string) of identifier in that file will be replaced by replacement-text before the program is compiled. For example,
#define PI 3.14159
replaces all subsequent occurrences of the symbolic constant PI
with the numeric constant 3.14159
. Symbolic constants enable you to create a name for a constant and use the name throughout the program. Later, if the constant needs to be modified throughout ...
Get C++ How to Program, 10/e 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.