A test question: What is the result of (false - ~0)
Why (false - ~0)
is 1
? On 32 bit machine ~0
is 11....11
where there are 32 1
bits right? Then false to int conversion is 00....00
also 32 times, right? So we subtract from 32 0
32 1
? Does it underflow and we get 1?
0
is int
→ ~0
is int
and equal -1
→ false
gets promoted to int
, which results in zero → your expression is calculated as (0 - (-1))
which equals 1
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With