Preprocessor Directives are special instructions processed by the C preprocessor before the actual compilation begins. They start with the # symbol and do not end with a semicolon (;).

Common Preprocessor Directives

1. #include

Used to include header files in a C program.

Syntax:

#include <stdio.h>     // Standard header file
#include "myfile.h"    // User-defined header file

Example:

#include <stdio.h>

int main()
{
    printf("Hello, World!");
    return 0;
}

2. #define

Used to define constants or macros.

Syntax:

#define PI 3.14159

Example:

#include <stdio.h>
#define PI 3.14159

int main()
{
    float r = 5;
    printf("Area = %.2f", PI * r * r);
    return 0;
}

3. #undef

Used to undefine a previously defined macro.

Example:

#define MAX 100
#undef MAX

Related Posts