Thursday 19 September 2013

Macros :
Macros are symbolic constants and they are used for improving the readability.
The general syntax for defining the macro is ,
#define macroname macroexpansion

e.g.#define MAX 50
Now,     MAX  is a macro and where ever we write MAX  it will be considered equivalent to 50.
And also ,
MAX=60;
will results in an error, as MAX  is replaced by 50 , so the statement means ,
50=60;
as we cannot assign one constant into another so it will give an error .
Consider the following code ,
       #include<iostream.h>
       #include<conio.h>
       #define PI 3.14
       void main()
       {
              float radius,area,circum;

              clrscr();

              cout<<endl<<"Enter the radius of the circle :";
              cin>>radius;

              //calculate the area of the circle

              area=PI * radius * radius;

              // calculate the circumference of the circle

              circum  = 2 * PI  * radius ;

              cout<<endl<<"Area of circle :" << area;

              cout<<endl<<"Circumference of the circle :"<<circum;

              getch();


}

No comments:

Post a Comment