Question:What will be output when you will execute following c code?#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;
}
+ ExplanationConsider on the expression:
x = 10 +- 10u + 10u +- 10;
10: It is signed integer constant.
10u: It is unsigned integer constant.
X: It is signed integer variable.
In any binary operation of dissimilar data type for example: a + b
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.
As we know operators enjoy higher precedence than binary operators. So our expression is:
x = 10 + (-10u) + 10u + (-10);
= 10 + -10 + 10 + (-10);
= 0
Note: Signed is higher data type than unsigned int.
So, Corresponding signed value of unsigned 10u is +10
[/b]Author:[/b]