Use of
  • #ifdef
  • #ifndef
  • #else
  • #undef
Code

#include <iostream.h>
#include <stdlib.h>
#define TeamName "Raiders"
#define Player_No 10
//#define identifier get_at_local
int main(void)
{
cout<<"Example of #define, #ifdef, #ifndef, #else,#undef\n";
cout<<"----proprocessor starts------------\n";
//---handle team name---------
// cin >> TeamName ;
#ifdef TeamName
cout<<"\nTeamName is defined.\n";
#else
cout<<"\nTeamName is not defined.\n";
#endif
//---handle Player_No---------
#ifndef Player_No
cout<<"\nPlayer_No is not defined\n";
#else
cout<<"\nPlayer_No is "<<Player_No<<endl;
cout<<"\nPlayer_No Belongs to "<<TeamName<<endl;
#endif

//---handle not defined---------
#ifdef custon
cout<<"\ncustom is defined\n"<<endl;
#else
cout<<"\ncustom is not defined!\n"<<endl;
#endif
//---erase out #defined with #undef---------
#undef Player_No
#ifndef Player_No
cout<<"Player_No is cleared out with undef and tested with ifndef\n"<<endl;
#else
cout<<"Player_No is "<<Player_No<<endl;
#endif
//system("pause");
cout<<"----proprocessor ends------------\n";
return 0;
}