I have this piece of code can you explain me the output
unsigned int x=3;
~x;
printf("%d",x);
output is 10
I am not able to make it how.
I have compiled the code on turbo c
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The code as you’ve posted it won’t compile. It will compile if you change
~xtox = ~x;, but then it won’t give the output “10”.The
~operator creates a bitwise inverse of the number given. In binary, the number 3 as an eight-bit integer is represented by the bits00000011. The~operator will replace every one of those bits with its opposite, giving11111100, which is 252 unsigned, or -4 signed.You declared
xas anunsigned int, which means a 32-bit unsigned value on most platforms. So your original value is00000000 00000000 00000000 00000011, and the inverse is11111111 11111111 11111111 11111100, or 4294967292.