12

Preprocesser in c

Embed Size (px)

DESCRIPTION

before actual compile.......some .....cont.....

Citation preview

Page 1: Preprocesser in c
Page 2: Preprocesser in c

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

Page 3: Preprocesser in c

Preprocessor DirectivesIn C

Muhammed Thanveer [email protected] Muhammed Thanveer MelayiTwitter ProfileLinkedin Profile

Page 4: Preprocesser in c

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

Page 5: Preprocesser in c

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

Page 6: Preprocesser in c

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; }

Page 7: Preprocesser in c

#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); #endifreturn 0;}

Output: 625

Page 8: Preprocesser in c

# error directive in c

Syntax : #errorit only issue an error message and this error message includes .Example #include<stdio.h>#ifndef __MATH_H#error First include then compile#elseint main(){ float a,b=25; a=sqrt(b); printf("%f",a); return 0;}#endifOutput: compiler error --> Error directive :First include then compile

Page 9: Preprocesser in c

Thank you

Page 10: Preprocesser in c

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.

Page 11: Preprocesser in c

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

Page 12: Preprocesser in c

Emarald Mall (Big Bazar Building)Mavoor Road, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550

NC Complex, Near Bus StandMukkam, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550

Cafit Square,Hilite Business Park,Near Pantheerankavu,Kozhikode

Start up VillageEranakulam,Kerala, India.Email: [email protected]

Contact Us