2+3 and 5 Are Not Equal in C
On this page (7sections)
Question: 2+3 and 5 are not equal In C Program.. How?:
#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.
Related Pages
- C Archive — Browse all C Archive.
- Confusing Array in C ( Array Representation and Initialization ) — More in c blog.
- The Use of * and & in C/C++ — More in c blog.
- Use of getch(),getche() and getchar() in C — More in c blog.