0

Why both printf gives different output?

int main(){ int a = 10; printf("%d",~a); printf("%u",~a); return 0; }

12th Oct 2020, 4:50 AM
C Lover
1 Resposta
+ 2
Because of the difference in the format specifier (conversion specifier), the first call displays the negated value in signed integer format, while the second call displays the negated value in unsigned integer format. Since the unsigned integer only supports positive values, a negative value is treated as maximum unsigned int value minus <a> -> (UINT32_MAX - <a>).
12th Oct 2020, 5:23 AM
Ipang