O'Reilly logo

Just Enough C/C++ Programming by Guy W. Lecky-Thompson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The #define Directive

The #define directive is used for two purposes. Both purposes discussed here involve basic substitution—in other words, the pre-processor substitutes one constant value for another whenever it is encountered in a source file. The way to use #define is to define a constant value that will be replaced by the pre-processor.

The pre-processor is capable of substituting a named value with a real value or even performing some basic expansion and evaluation tasks. The four key #define keywords most commonly used in C programming are as follows:

#define <constant_name> <coinstant_value>


#ifdef <constant_name>

#ifndef <constant_name>

#endif

The #define statement defines a constant <constant_name> and associates it with <constant_value> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required