+ 1

find output with reason:- main() { if(sizeof(int)>-1) printf("Hello"); else printf("Hii") }

https://code.sololearn.com/cW6t25iCkoZ1/?ref=app

14th Dec 2019, 11:02 AM
Amit Dubey
Amit Dubey - avatar
4 Answers
+ 3
I guess sizeof returns an unsigned integer. In that case, 4 < -1 because you're comparing unsigned and signed values. That's why it's printing Hii
14th Dec 2019, 11:22 AM
Théophile
Théophile - avatar
+ 6
sizeof(int) is of type size_t, which is an unsigned integer type. So in the expression if(sizeof(int) > -1), -1 is converted to an unsigned integer, which is very big.
14th Dec 2019, 11:33 AM
Prathvi
Prathvi - avatar
+ 3
sizeof(int)=4 (signed) and -1 =4,294,967,295(signed) So 4>4,294,967,295 is false . That's why its printing Hii.
14th Dec 2019, 2:05 PM
Prathvi
Prathvi - avatar
0
why it is not so when i print the value of sizeof(int), it does not show any unsigned value. why??
14th Dec 2019, 12:15 PM
Amit Dubey
Amit Dubey - avatar