Monday, July 28, 2014

Macro Program in C

Macro in C
       If the macro name appears inside its own expansion, then it is not expanded.
     So don't try to write recursive macros like this one ...
  
     #define FACTORIAL(k)  k==0?1 : k*FACTORIAL(k-1);
   
      This is Incorrect....
     

   #include<stdio.h>
#include<conio.h>
   #define MAX(FNAME,DTYPE)
                    DTYPE  FNAME(DTYPE x,DTYPE y)
                {
                        return x>y?x:y;
}
  MAX(max_int ,int)
  MAX(max_float ,float)
  MAX(max_double ,double)
    int main(void)
{
   int p;
  float q;
double r;
p=max_int(3,9);
q=max_float(7.4,5.7);
r=max_double(12.34,13.54);
printf("p=%d, q=%f ,r=%2lf \n",p,q,r);
return 0;
}
 

No comments:

Post a Comment

Featured Post

What is JavaScript? What is the role of JavaScript engine?

  The JavaScript is a Programming language that is used for converting static web pages to interactive and dynamic web pages. A JavaScript e...