I have assigned -1 to unsigned int and assuming it would produce an error I compiled the code, much to my astonishment it didn't. I can't understand the reason behind it.
I have tried printing the values to check them manually, but it always shows -1.
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
int main(int argc, char *argv[]) {
unsigned int x = -1;
printf("%u\n", x);
int y = -1;
printf("%d\n", y);
if (x == y) {
printf("\nsame");
} else {
printf("n s");
}
return 0;
}
the expected result would have been an error or a warning but it compiled as is.