Programming in C: Unit I (d): Preprocessor Directives

Introduction of Preprocessor Directives

Programming in C

The preprocessor is a program that processes the source code before it passes through the compiler.

Unit – I : Basics of C Programming

CHAPTER 4 : PREPROCESSOR DIRECTIVES

Takeaways

• Preprocessor directives

• #error directive

• Pragma directives

• Predefined macro names

• Conditional directives

INTRODUCTION OF PREPROCESSOR DIRECTIVES

The preprocessor is a program that processes the source code before it passes through the compiler. It operates under the control of preprocessor directive which is placed in the source program before the main(). Before the source code is passed through the compiler, it is examined by the preprocessor for any preprocessor directives. In case the program has some preprocessor directives, appropriate actions are taken (depending on the directive) and the source program is handed over to the compiler.

Preprocessor directives are lines included in the c program that are not program statements but directives for the preprocessor. The preprocessor directives are always preceded by a hash sign (#) directive. The preprocessor directive is executed before the actual compilation of program code begins. Therefore, the preprocessor expands all the directives and takes the corresponding action before any code is generated by the program statements.

The preprocessor directives are only one line long because as soon as a newline character is found, the preprocessor directive is considered to end. No semico- lon (;) can be placed at the end of a preprocessor direc- tive. However, the preprocessor directives may contain a comment (which will be simply ignored).

Programming Tip: Preprocessor directives must start with a hash () sign.

Note

In order to extend a preprocessor directive to multiple lines, place a backslash character (\) as the last character of the line. This means that the line is continued in the line following it.

Although the preprocessor directive is usually placed before the main (), practically speaking, it can appear anywhere in the program code. However, if written in between, the directive will be applied only in the remainder of the source file. The advantages of using preprocessor directives in a C program include:

• Program becomes readable and easy to understand.

• Program can be easily modified or updated.

• Program becomes portable as preprocessor directives make it easy to compile the program in different execution environments.

• Due to the aforesaid reasons, the program also becomes more efficient to use.

Programming in C: Unit I (d): Preprocessor Directives : Tag: : Programming in C - Introduction of Preprocessor Directives


Programming in C: Unit I (d): Preprocessor Directives



Under Subject


Programming in C

CS3251 2nd Semester CSE Dept 2021 | Regulation | 2nd Semester CSE Dept 2021 Regulation



Related Subjects


Professional English II

HS3251 2nd Semester 2021 Regulation | 2nd Semester Common to all Dept 2021 Regulation


Statistics and Numerical Methods

MA3251 2nd Semester 2021 Regulation M2 Engineering Mathematics 2 | 2nd Semester Common to all Dept 2021 Regulation


Engineering Graphics

GE3251 eg 2nd semester | 2021 Regulation | 2nd Semester Common to all Dept 2021 Regulation


Physics for Electrical Engineering

PH3202 2nd Semester 2021 Regulation | 2nd Semester EEE Dept 2021 Regulation


Basic Civil and Mechanical Engineering

BE3255 2nd Semester 2021 Regulation | 2nd Semester EEE Dept 2021 Regulation


Electric Circuit Analysis

EE3251 2nd Semester 2021 Regulation | 2nd Semester EEE Dept 2021 Regulation


Physics for Electronics Engineering

PH3254 - Physics II - 2nd Semester - ECE Department - 2021 Regulation | 2nd Semester ECE Dept 2021 Regulation


Electrical and Instrumentation Engineering

BE3254 - 2nd Semester - ECE Dept - 2021 Regulation | 2nd Semester ECE Dept 2021 Regulation


Circuit Analysis

EC3251 - 2nd Semester - ECE Dept - 2021 Regulation | 2nd Semester ECE Dept 2021 Regulation


Materials Science

PH3251 2nd semester Mechanical Dept | 2021 Regulation | 2nd Semester Mechanical Dept 2021 Regulation


Basic Electrical and Electronics Engineering

BE3251 2nd semester Mechanical Dept | 2021 Regulation | 2nd Semester Mechanical Dept 2021 Regulation


Physics for Civil Engineering

PH3201 2021 Regulation | 2nd Semester Civil Dept 2021 Regulation


Basic Electrical, Electronics and Instrumentation Engineering

BE3252 2021 Regulation | 2nd Semester Civil Dept 2021 Regulation


Physics for Information Science

PH3256 2nd Semester CSE Dept | 2021 Regulation | 2nd Semester CSE Dept 2021 Regulation


Basic Electrical and Electronics Engineering

BE3251 2nd Semester CSE Dept 2021 | Regulation | 2nd Semester CSE Dept 2021 Regulation


Programming in C

CS3251 2nd Semester CSE Dept 2021 | Regulation | 2nd Semester CSE Dept 2021 Regulation