C Programming: Presented by A.M.Shyam Sundar
C Programming: Presented by A.M.Shyam Sundar
PRESENTED BY
A.M.SHYAM SUNDAR.
1
Objectives
Introduction of preprocessor.
Types of preprocessor directives.
Defining a symbolic constants/macros.
2
Preprocessor
Preprocessor is a program.
3
Compiling C Programs
C compiler
Easy to
Develop program
Read programs
Modify programs
Portable
Reuse
6
Types of preprocessor directives
CM304.87 7
Types of preprocessor directives
Contd..
7) #elif
8) #endif
9) #undef
10) #error
11) #line
12) #pragma
8
Types of preprocessor directives
Preprocessor Meaning
Directive(s)
#include Treats text in the file specified by filename as if it
appeared in the current file.
#define Defines a macro/Symbolic constant.
#if , #ifdef, #ifndef, #else, Conditional compilation directives.
9
The #define Preprocessor Directive
1)Symbolic Constants
replacement value.
CM304.87 10
The #define Preprocessor Directive
#define FALSE 0
To undefine a macro
CM304.87 12
The # define preprocessor directive
2)Macros
#define IDENTIFIER(arg1,agr2,….agrn) body
agr1,agr2…agrn are arguments, body is the
body of the macro.
A macro without arguments is treated like a
symbolic constant.
When the macro is called, the call is replaced
by its body.
Well suited for small functions and functions
are called frequently.
13
The # define preprocessor directive
Contd..
Function Macro
Function call is nothing but Macro call is nothing but
branching. substitution.
Program execution is slow. Program execution is fast.
Example
body
Name argument
#define CIRCLE_AREA( x ) ( PI * ( x ) * ( x ) )
Calling Macro
area = CIRCLE_AREA( 4 );
to become
area = ( 3.14159 * ( 4 ) * ( 4 ) );
15
Example
CM304.87 16
Nested Macros
CM304.87 17
Example
CM304.87 18
An optimist is a person who sees a green light everywhere.
The pessimist sees only the red light. But the truly wise
person is color blind.
THANK YOU.
19