c - comparison of signed and unsigned numbers -
this question has answer here:
here question shown below , answers comes true.i know there promotion happen when compare signed , unsigned.can please tell me how signed value gets promoted?
main() { signed int = -5; unsigned int b = 2147483648; if(a > b) printf("true\n"); else printf("false\n"); }
advanced maddy
try printing out converted value , see goes on:
int main(int argc, char **argv) { signed int = -5; unsigned int ua = a; unsigned int b = 2147483648; printf("a=%d ua=%u b=%u\n", a, ua, b); if(a > b) printf("true\n"); else printf("false\n"); }
prints
a=-5 ua=4294967291 b=2147483648 true
share , enjoy.
Comments
Post a Comment