+ 5
Can you explain me that why the output is -11?
#include<stdio.h> int main() { unsigned int var = 10; printf("%d", ~var); return 0; }
4 Respuestas
0
Thank you now I understand
0
Can someone explain this a bit more clear, please
0
Can someone explain this a bit more clear, please
- 1
Above code gives -11 as output of printf.
var is type of unsigned int,
var is assigned with 10,
operator ~var converts var to complement of 10.
printf %d coverts it to integer while printing it's representation makes it -11
in 32 bit binary representation
10 => 0x0000000A
-11 => 0xFFFFFFF5
in C language int is represented as 2's complement.
That results in to print -11.
var contains after complement in 32 bits as
0xFFFFFFF5
2's complement of above is
0x0000000B
it is 11 in decimal representation
That's why print with format %d prints -11 in output.