The document discusses C preprocessor directives. The C preprocessor is a separate step from compilation that performs text substitution. Preprocessor directives like #include, #define, #ifdef control the preprocessing. #include inserts a header file. #define defines a macro. #ifdef checks if a macro is defined. Preprocessor directives make programs easier to develop, read and modify. Examples show using #include, #define, #ifdef and #error directives.
A Secure and Reliable Document Management System is Essential.docx
C Preprocessor Directives
1.
2. Disclaimer: This presentation is prepared by trainees of
baabtra.com as a part of mentoring program. This is not
official document of baabtra.com – Mentoring Partner
3. Preprocessor Directives
In C
Muhammed Thanveer Melayi
Muhammedthanveermelayi@yahoo.com
Muhammed Thanveer Melayi
Twitter Profile
Linkedin Profile
4. What is Preprocessors
The C Preprocessor is not part of the compiler, but is a
separate step in the compilation process. In simplistic
terms, a C Preprocessor is just a text substitution tool and
they instruct compiler to do required pre-processing before
actual compilation
All preprocessor commands begin with a pound symbol (#). It must be
the first nonblank character, and for readability, a preprocessor directive
should begin in first column
5. important preprocessor directives
Directive and Description
The unconditional directives are:
#include - Inserts a particular header from another file
#define - Defines a preprocessor macro
#undef - Undefines a preprocessor macro
The conditional directives are:
#ifdef - If this macro is defined
#ifndef - If this macro is not defined
#if - Test if a compile time condition is true
#else - The alternative for #if
#elif - #else an #if in one statement
#endif - End preprocessor conditional
Other directives include:
# - Stringization, replaces a macro parameter with a string
constant
## - Token merge, creates a single token from two adjacent ones
6. Use of the preprocessor
programs easier to develop
easier to read
easier to modify
example
#include <stdio.h>
#define PI 3.1415
int main()
{
int radius;
float area;
printf("Enter the radius: ");
scanf("%d",&radius);
area=PI*radius*radius;
printf("Area=%.2f",area);
return 0;
}
7. #ifdef and #endif in c
It only checks identifier has been defied or not.
#ifdef <Identifer>
-------------
-------------
#else
-------------
-------------
#endif
Example
#include<stdio.h>
#define ABC 25
#define PQR "Exact Help"
int main(){
int num = 3;
#ifdef ABC
printf("%d",ABC * ABC);
#else
printf("%s",PQR);
#endif
return 0;
}
Output: 625
8. # error directive in c
Syntax : #error
it only issue an error message and this error message includes .
Example
#include<stdio.h>
#ifndef __MATH_H
#error First include then compile
#else
int main(){
float a,b=25;
a=sqrt(b);
printf("%f",a);
return 0;
}
#endif
Output: compiler error --> Error directive :First include then compile
10. Want to learn more about programming or Looking to become a good programmer?
Are you wasting time on searching so many contents online?
Do you want to learn things quickly?
Tired of spending huge amount of money to become a Software professional?
Do an online course
@ baabtra.com
We put industry standards to practice. Our structured, activity based courses are so designed
to make a quick, good software professional out of anybody who holds a passion for coding.
11. Follow us @ twitter.com/baabtra
Like us @ facebook.com/baabtra
Subscribe to us @ youtube.com/baabtra
Become a follower @ slideshare.net/BaabtraMentoringPartner
Connect to us @ in.linkedin.com/in/baabtra
Give a feedback @ massbaab.com/baabtra
Thanks in advance
www.baabtra.com | www.massbaab.com |www.baabte.com
12. Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Cafit Square,
Hilite Business Park,
Near Pantheerankavu,
Kozhikode
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com