Monday, January 25, 2010

#define Macroprocessor

One of macroprocessor #define used to define value for variable. The value will be constant for that variable. Can't change in run time.
eg:
#define a 10
'a' value is constant has always 10.

#define can be used before all functions or inside functions like usual variable declaration.


#include< stdio.h >
#define a 1
main( )
{
#define b 2
printf("%d %d", a,b);
}

not only used for define values but also define function.
#define f(a,b) a+b
this function will get two arguments a and b and return addition of them.


#include< stdio.h >
#define fn(a,b,c) a+(b*c)
main()
{
printf("%d",fn(1,2,3));
}


output:
7

0 comments:

Post a Comment