#include <stdio.h>
int main(void)
{
if (sizeof(int) > -1)
printf("True");
else
printf("False");
}
It prints False
. Why doesn't sizeof() return a value in the if
?
#include <stdio.h>
int main(void)
{
if (sizeof(int) > -1)
printf("True");
else
printf("False");
}
It prints False
. Why doesn't sizeof() return a value in the if
?
sizeof
is not a function, it's an operator. The parentheses are not part of the operator's name.size_t
, which causes "the usual arithmetic conversions" in which -1
is converted to unsigned, in which case it's a very large number.Basically you're comparing 4 > 0xffffffffu
, or something close to that at least. See this question for details.