Namara

Code daily. Without assist.

Today's code

/* c/read */

#include <stdio.h>

int main(void) {
    int x = -1;
    unsigned int y = 1;

    printf("%d\n", x < y);
}

What does this print?

Answer

0. In the comparison, the usual arithmetic conversions apply: since x and y have the same rank, the signed x is converted to unsigned int before < runs. -1 becomes the largest possible unsigned int, which is never less than 1u. This is well-defined by the standard — just easy to forget once you've stopped thinking about signedness on every line.