#include<stdio.h>
int main()
{
signed
x;
unsigned
y;
x = 10 +- 10u + 10u +- 10;
y = x;
if(x==y)
printf("%d %d",x,y);
else
if(x!=y)
printf("%u %u",x,y);
return 0;
return 0;
}
Output: 0 0
Explanation:
x
= 10 +- 10u + 10u +- 10;
10: It is
signed integer constant.
10u: It is
unsigned integer constant.
X: It is
signed integer variable.
Lower data type operand always
automatically type casted into the operand of higher data type before
performing the operation and result will be higher data type.
Signed is higher data type than unsigned int. So our
expression is:
x = 10 +
(-10u) + 10u + (-10);
=
10 + -10 + 10 + (-10);
= 0
Thank you for this explaination
ReplyDelete