+ 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; }

2nd Jun 2020, 10:55 AM
Shreyam Sarkar
6 ответов
0
Thank you now I understand
2nd Jun 2020, 1:00 PM
Shreyam Sarkar
0
Can someone explain this a bit more clear, please
14th Sep 2021, 3:52 PM
Ayush Jha
Ayush Jha - avatar
0
Can someone explain this a bit more clear, please
22nd May 2022, 5:12 PM
Rashedul Islam
- 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.
2nd Jun 2020, 12:23 PM
DHANANJAY PATEL
DHANANJAY PATEL - avatar