Preprocessing directives are statements that begin with a # token. These statements are processed prior to compilation, thus the compiler never sees them (hence the term, preprocessed). Preprocessing primarily allows a translation unit (a source file) to include code from other files (header files), via the #include directive, as well as to conditionally compile code using the #ifdef, #ifndef, #else and #endif directives in conjunction with the #define directive.
The #define directive is also used to define macros. Macros may be assigned a value and wherever the symbol appears in your code, that symbol is replaced with the value by the preprocessor. Macros can also be used to define functions for inline expansion. However, because the compiler never sees the macro definition, it cannot help you debug them. They are not type safe and are best avoided whenever possible.
Chat with our AI personalities