C++ Preprocessor Directives

747 views
612 views

Published on

Simple and brief account of C++ preprocesor directives has been presented for C++ newbies.

~ Wasif Altaf

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
747
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

C++ Preprocessor Directives

  1. 1. Introduction to C ++
  2. 2. DEFINITION Preprocessor directives are not program statements but directives for PREPROCESSOR
  3. 3. AVAILABLE • • • • • #define #undef #ifdef #ifndef #error • • • • • #pragma #if #endif #else #elif
  4. 4. #define #define identifier replacement #define PI 3.14159 const float PI = 3.14159;
  5. 5. #include<iostream.h> #define PI 3.14159 void main(void) { const float pi = 3.14159; EXAMPLE PI: 3.14159 pi: 3.14159 pi*PI: 9.86958 cout<<"PI: "<< PI <<endl<<endl; cout<<"pi: "<< pi << endl << endl; cout<<"pi*PI: "<<pi*PI<<endl<<endl; } // main function ends here
  6. 6. DEFINING MACROS #define m-identifier replacement #define square(x) (x)*(x) double square(double x){return x*x;}
  7. 7. EXAMPLE #include<iostream.h> Square of 9 is: 81 Square of 9+1 is: 100 #define square(x) (x)*(x) double sqr(double x){return x*x;} Square of 9 is: 81 void main(void){ int value = 9; cout<<"Square of "<<value<<" is: "<<square(value)<<endl; cout<<"Square of "<<value<<"+1 is: "<<square(value+1)<<endl; cout<<"Square of "<<value<<" is: "<<sqr(double(value)); }// main function ends here
  8. 8. OUTPUT Square of 9 is: 81 Square of 9+1 is: 100 Square of 9 is: 81
  9. 9. Questions & Answers
  10. 10. Thanks

×