Working with Define in C++ programming by using the 'define' keyword. 'define' keyword is a preprocessor directive that allows you to define a macro, essentially a symbolic name.
#include<iostream.h>
#include<conio.h>
#define bilal 13 //defining 'bilal' is 13.
void main()
{
int i;
for(i = 1; i <= bilal; i++) //loop looping from 0 to less then
cout<<i<<endl; //Or equal to defined 'bilal' Value.
getch();
}
#include<iostream.h>
#include<conio.h>
#define AND && //defining 'AND'.
#define ARANGE (a > 25 AND a < 50) //defining 'ARANGE'.
void main()
{
int a = 30;
if(ARANGE) //if 'ARANGE' mean if 'a' value greater then 25 And
{ //less then 50 then
cout<<"Within range"; //print this.
}
else
{
cout<<"Out of range";
}
getch();
}
#include<iostream.h>
#include<conio.h>
#define MyVal cout<<"This is First Line"<<endl; //defining.
#define MyVal2 cout<<"This is 2nd Line"<<endl;
void main()
{
MyVal2 //using defined.
MyVal
getch();
}