Dec 20, 2011

Program : Using #define Function

Using #define Function

#define use to define a function or value or any work that particular keyword replace with that work like to display on screen i always use cout << everytime i replace it with a keyword print so next time when i require cout << then i have to use only print rest all is same like print "AZ"; //it will print AZ. Check Out Program.


Let Check Out Example :-

//Using #define function
#include<iostream.h>
#include<conio.h>

#define pi 3.14
/* Here i Define a Variable pi which i assign a value that 3.14(here)
*/
#define print cout <<
/* It must declare after Header File
Syntax :-
#define variable_name function or value

Like here i define variable print which function is to replace cout <<
So i dont have to write cout << i can write directly print check out main function*/

int main()
{
print pi; // print = cout << and pi = 3.14
// it will print 3.14 on screen
print "\nHello world"; // print hello world
    getch();
    return 0;
}


Output





0 comments:

Post a Comment