Articles‎ > ‎Technical Articles‎ > ‎

2+3 and 5 are not equal In C

posted Aug 11, 2009, 8:04 AM by Thiyagaraaj M   [ updated Aug 29, 2011, 11:41 AM ]
2+3 and 5 are not equal In C

what is the output of the program?

Example Program:

#define Square( X )  ( X * X ) 

void main( )
    {
        int value1,value2;
        value1 = Square( 2+ 3 );
        value2 = Square( 5 );

        if ( value1 == value2 )
            printf("Equal");
        else
            printf("Not Equal');
    }


Output:
    Not Equal.

Description:


The Macro replaces the code when there is necessity of the code.From the above program, we can able to understand the usage of Macro.

The value of value1 = 11.
The value of value2 = 25.

How ?
When the code Square(X) (X*X) replaces,we get,

Iteration 1:
value1= (2+3*2+3)
Therefore,value1=11.

Iteration 2:
value2= 5 * 5
Therefore,value2= 25.

Conclusion:

So, we come to a conclusion that 2+3 and 5 is not equal always.
And hence,the Macro should be used in appropriate situations,otherwise Macro will give wrong result.