If I use wrong format specifier like this :
unsigned int i = -1;
printf("%d\n", i);
It is invoked undefined behaviour because %u
format specifier for unsigned
.
C11 standard ยง 7.21.6.1(P9):
If a conversion specification is invalid, the behavior is undefined.282) If any argument is not the correct type for the corresponding conversion specification, the behavior is undefined.
But, If I write like this:
unsigned int i = -1;
printf("%d\n", (int)i); // unsigned to signed
Is it also undefined behaviour?