int main()
{
unsigned int a = 1000;
int b = -1;
if (a>b) printf("A is BIG! %d\n", a-b);
else printf("a is SMALL! %d\n", a-b);
return 0;
}
the answer to this question is "a is small,1001 "
so I found explaination to this ques and came to some conclusions ,but can someone verify is it correct or not?
1.Here when we compare b(signed int) and a(unsigned int),b is type casted to unsigned and its value is taken as MAX-1,where MAX is the largest unsigned number possible ,so control goes to else condition
2.now a-b=1000-(MAX-1) ,=(-MAX+1001) which is negative and as it has to be treated as unsigned integer its value is MAX+ (-MAX+1001)=1001
3.The presence of "%d " in printf has no effect ,the result will be unsigned always