Preprocessor Directives

📘 C 👁 27 views 📅 Dec 22, 2025
⏱ Estimated reading time: 1 min
Learn #define, #include, conditional compilation.

Preprocessor directives are instructions given to the compiler before the actual compilation starts.
They begin with the symbol # and do not end with a semicolon.


Common Preprocessor Directives

  1. #include

  2. #define

  3. #undef

  4. #if, #else, #elif, #endif

  5. #ifdef, #ifndef


1. #include Directive

Used to include header files.

Syntax

#include #include "file.h"
  • < > – System header files

  • " " – User-defined header files


2. #define Directive

Used to define macros or symbolic constants.

Syntax

#define PI 3.14

Macro Example

#define SQUARE(x) (x * x)

3. #undef Directive

Used to undefine a macro.

#undef PI

4. Conditional Compilation Directives

#if, #else, #endif

#if x > 10 statements; #else statements; #endif

#ifdef and #ifndef

#ifdef PI statements; #endif #ifndef MAX #define MAX 100 #endif

Predefined Macros

MacroDescription
__DATE__Current date
__TIME__Current time
__FILE__File name
__LINE__Line number

Advantages of Preprocessor Directives

  • Improves code readability

  • Enables conditional compilation

  • Saves development time

  • Supports code reuse


Summary

  • Preprocessor works before compilation

  • Directives start with #

  • #include adds header files

  • #define creates macros

  • Conditional directives control compilation.


🔒 Some advanced sections are available for Registered Members
Register Now

Share this Post


← Back to Tutorials

Popular Competitive Exam Quizzes