2+3 and 5 are not equal In C
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.
Read More Articles
- Use of getch(),getche() and getchar() in C
- Switch Case Statement Example Program In C Programming Language
- C Character Set
- Convert a Floating-point value to an Integer in C
- Data Input and Output gets and puts Example Program In C
- Special Operators In C
- Pointer Representation and Pointer Example Programs
- C Data Input and Data Output
- Simple While Loop Example Program In C Programming Language
- Data Output printf and putchar Example Program In C
- C Introduction
- C Operators
- Storage Classes In C
- C Pointers
- File Management
- C Identifiers
- Loop Control Statements
- Hello World - Simple C Program
- C Array
- Single Character Output Function : putchar()
- C Reserve Words
- C Specific Properties and Implementation
- If else Statement Example Program In C Programming Language
- If Statement Example Program In C Programming Language
- Confusing Array in C ( Array Representation and Initialization )