Documentos de Académico
Documentos de Profesional
Documentos de Cultura
ANDHRA PRADESH
Name :M.Subramanyam
Designation :Senior Lecturer
Branch :Computer Engg.
Institute :Q.Q.Govt.Polytechnic,Hyderabad.
Year/Semester :III Semester
Subject :UNIX & C
Subject Code :CM-304
Topic :Preprocessor directives
Duration :50 Min
Sub Topic :Header files and Conditional
Directives
Teaching Aids :PPTs, Animations
CM304.88 1
Recap
What is a preprocessor?
What are the different types of preprocessor
directives?
What is a macro?
What are the advantages of macros?
CM304.88 2
Objectives
Header files.
Defining Conditional compilation directives.
CM304.88 3
Header Files (#include)
CM304.88 4
Header Files (#include)
Contd..
The #include directive loads specified file
content in the current program.
The macros and functions of loaded file can be
called in the current program.
The included file is also compiled with current
program.
Types of header files
1. predefined
2. user defined
CM304.88 5
Predefined header files
Come with the compiler.
Including a predefined header file in a program.
Syntax:
1)#include<filename>
2)#include”filename”
< > means Preprocessor will search for the
file only in the standard directory.
When the filename is included within “ “
means preprocessor will search for the file in
the current working directory and in the
standard directory.
CM304.88 6
Predefined header files
Example
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<string.h>
#include<ctype.h>
CM304.88 7
User defined header file
2)#include”filename”
CM304.88 8
Example1
CM304.88 9
Example2
CM304.88 10
Conditional compilation directives
1)#ifdef
Syntax: #ifdef IDENTIFIER
{
statement1;
statement2;
--------------;
--------------;
}
#endif
CM304.88 11
Conditional compilation directives
Contd..
CM304.88 12
Example
CM304.88 13
#ifdef…#else…#endif
Syntax
#ifdef IDENTIFIER
{
Statement(s);
}
#else
{
Statement(s)
}
#endif
CM304.88 14
#ifdef…#else…#endif
Contd..
CM304.88 15
Example1
CM304.88 16
Example2
CM304.88 17
#ifndef
Syntax:
#ifndef IDENTIFIER
{
statement(s)
}
#endif
If IDENTIFIER is not defined then statement(s)
is/are compiled and executed.
CM304.88 18
Example
CM304.88 19
Summary
CM304.88 20
Quiz
a)conio.h
b)string.h
c)math.h
d)stdio.h
CM304.88 21
Quiz
a)conio.h
b)string.h
c)math.h
d)stdio.h
CM304.88 22
Quiz
a)stdio.h
b)ctype.h
c)process.h
d)string.h
CM304.88 23
Quiz
a)stdio.h
b)ctype.h
c)process.h
d)string.h
CM304.88 24
Quiz
a) #ifdef
b) #ifndef
c) #else
a) #ifdef
b) #ifndef
c) #else
CM304.88 27