The output of this program is -13. I have never fully understood ~ operator in C. Why does it give -13 as output? How to limit ~ operator to just 4 bits of a number?
<
it's a bitwise operator (one's complement ) that works this way :
~00000101 // 5 =11111010 // 250
so the 1s become 0s and vise versa but in some cases the sign bit is activated and you'll get unexpected results