Upload
wasif-altaf
View
553
Download
2
Embed Size (px)
DESCRIPTION
Simple and brief account of C++ preprocesor directives has been presented for C++ newbies. ~ Wasif Altaf
Citation preview
Introduction to C ++
Preprocessor directives are not program statements but
directives for
PREPROCESSOR
DEFINITION
• #define• #undef• #ifdef• #ifndef• #error
AVAILABLE
• #pragma
• #if• #endif• #else• #elif
#define identifier replacement
#define
#define PI 3.14159
const float PI = 3.14159;
#include<iostream.h>
#define PI 3.14159void main(void){
const float pi = 3.14159; cout<<"PI: "<< PI <<endl<<endl; cout<<"pi: "<< pi << endl << endl; cout<<"pi*PI: "<<pi*PI<<endl<<endl;
} // main function ends here
EXAMPLEPI: 3.14159
pi: 3.14159
pi*PI: 9.86958
#define square(x) (x)*(x)
DEFINING MACROS
#define m-identifier replacement
double square(double x){return x*x;}
EXAMPLE#include<iostream.h>
#define square(x) (x)*(x)double sqr(double x){return x*x;}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
Square of 9 is: 81
Square of 9+1 is: 100
Square of 9 is: 81
OUTPUT
Square of 9 is: 81
Square of 9+1 is: 100
Square of 9 is: 81
Questions &
Answers
Thanks