19.6.20

c program enclosing the variable in the macro expansion


IMPORTANCE OF ENCLOSING THE VARIABLES IN THE MACRO EXPANSION WITHIN PARENTHESIS
#include<math.h>
#define MAC(x,y)sqrt(x*x+y*y)
float fun(int x,int y)
{
    return sqrt(x*x+y*y);

}
void main()
{

    int a=3,b=4;
    float p,q,r,s;
    p=fun(a,b);
    q=fun(a+1,b+1);
    r=MAC(a,b);
    s=MAC(a+1,b+1);
    printf("Using functions:%f,%f\n",p,q);
    printf("Using macros:%f,%f",r,s);
}
OUTPUT
Using functions: 5.0000000,6.403124
Using macros      5.0000000,4.000000

No comments:

Post a Comment

JAVA program pattern 2

import java.util.Scanner; public class pattern3 { public static void main(String args[]) { int i,j; Scanner sc=new Scanner(System.in); Syste...