Why this works?

1
2
3
4
5
6
7
8
9
#include <stdio.h>

int main (void)
{
    unsigned int world=0;
    printf ("%d",world-1);
    return 0;
}


when i do, world-1, it becomes negative, i though it should give me an error since world is unsigned. anyone know why the case?
When you do that, an underflow happens, the result being 0xFFFFFFFF. That number and -1 have the same binary representation. So it will print as -1 if you treat it like a signed integer.
Topic archived. No new replies allowed.