Directive #define creates compile-time constants, or macros. - C Preprocessor

C examples for Preprocessor:Preprocessor Operators

Introduction

The following directive sets the value of 3.14 to PI.

#define PI 3.14 /* macro definition */

The preprocessor will scan the code and change any occurrences of this constant.

float f = PI; /* f = 3.14 */

By convention, constants should be named in uppercase letters with each word separated by an underscore.

Undefine

A #define directive should not be used to override a previously defined macro.

To redefine an existing macro, undefine the macro first using the #undef directive.

#undef PI /* undefine */
#undef PI /* allowed */

Related Tutorials