Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

var=~7 how to interpret this line

0 votes
asked Jan 8, 2019 by anonymous

1 Answer

0 votes
answered Jan 22, 2019 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.
...