sizeof() operator in if-statement

c, sizeof

Solution

- `sizeof` is not a function, it's an operator. The parentheses are not part of the operator's name.

- It's failing because the value generated has the unsigned type `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.

Problem

``` #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`?

Original source

Related problems