

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- What are C# pre-processor directives?
- Explain the pre-processor directives in C language
- 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#?
- What are Shell Commands?
- What are the DDL commands in DBMS?
- What are the DML commands in DBMS?
- What are the TCL commands in DBMS?
- What are the DCL commands in DBMS?
- What are the key elements of Superscalar Processor?
- What are the different commands used in MySQL?
- What are the shift operations in C language?
- What are the predefined functions in C language?
- What are the special symbols in C language?