
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
What are the Pre-processor Commands in C language?
The preprocessor is a program that sends the source code before it passes through the compiler. It operates under preprocessor directives which begin with the symbol #.
Types
The three types of preprocessor commands are as follows −
Macro substitution directives.
File inclusion directives.
Compiler control directives.
Macro substitution directives
It replaces every occurrence of an identifier by a predefined string.
The syntax for defining a macro substitution directive is as follows −
# define identifier string
For example,
#define PI 3.1415 #define f(x) x *x #undef PI
Example
Following is the C program for the macro substitution directive −
#define wait getch( ) main ( ){ clrscr ( ); printf ("Hello"); wait ; }
Output
When the above program is executed, it produces the following result −
Hello
File inclusion directives
An external file containing functions (or) macro definitions can be included by using #include directive.
The syntax for file inclusion directive is as follows −
# include <filename> (or) #include "filename"
Example
Following is the C program for the file inclusion directive −
#include <stdio.h> main ( ){ printf ("hello"); }
Output
When the above program is executed, it produces the following result −
Hello
The definition of the function printf ( ) is present in <stdio.h>header file.
Compiler control directives
C preprocessor offers a feature known as a conditional compilation, which can be used to switch ON (or) OFF a particular line (or) group of lines in a program.
Example
Following is the C program for the compiler control directive −
#if, #else, #endif etc. #define LINE 1 #include<stdio.h> main ( ){ #ifdef LINE printf ("this is line number one"); #else printf("This is line number two"); #endif }
Output
When the above program is executed, it produces the following result −
This line number one
- Related Articles
- Explain the pre-processor directives in C language
- What are C# pre-processor directives?
- What is a pre-processor directive in C#?
- What is #define pre-processor directive in C#?
- What is a conditional pre-processor directive in C#?
- Post and Pre incremented of arrays in C language
- How to use Pre-defined mathematical function in C language?
- What are the DDL commands in DBMS?
- What are the DML commands in DBMS?
- What are the DCL commands in DBMS?
- What are the TCL commands in DBMS?
- What are the key elements of Superscalar Processor?
- What are Shell Commands?
- What are the predefined functions in C language?
- What are the shift operations in C language?
