-1 ??? code: #include int main...">

Why sizeof (int) is not greater than -1?

this is my C code: why is the output "False" ?????

why 4> -1 ???

code:

#include <stdio.h> int main() { if (sizeof(int) > -1) printf("True"); else printf("False"); return 0; } 
+3
source share
2 answers

Because sizeof (int) is unsigned. Thus, -1 is converted to a large unsigned value.

+11
source

Because sizeof gives a value of type size_t , which is an unsigned type. In the expression > regular arithmetic conversions convert -1 to an unsigned type, which is the result type > . The resulting value will be a large positive value.

To use the expected behavior:

 (int) sizeof (int) > -1 
+4
source

All Articles