-1

I ran this code:

#include <stdlib.h>


int main(){

    unsigned int x = -1;
    printf("%d\n", x);
}

And it still works but it shouldn't. Because some people say that "Unsigned variables cant handle negative numbers".

Cracker
  • 43
  • 5

1 Answers1

0

You need to use %u to print unsigned integers. As luck would have it, you are taking an integer (-1), converting to an unsigned int, and then treating that as an integer again (%d)

#include <stdlib.h>


int main(){

    unsigned int x = -1;
    printf("%u\n", x);
}
robthebloke
  • 9,331
  • 9
  • 12