var=~7 how to interpret this line

0 votes
asked Jan 8 by anonymous

1 Answer

0 votes
answered Jan 22 by Jyothi_Rk
#include <stdio.h>
void main()
{
    int var= ~7;
    printf("%d\n",var);
}

if you write a code like this, then the output will be -8.Reason is simple

7  in binary is 0111

not of 7=(~7) in binary is 1000   = 8  and note that the MSB is 1,hence the value will be considered as negative.Hence ~7= -8.

In other words ,we can easily remember it as : NOT OF A NUM= -(NUM+1)
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...