What is a difference between unsigned int and signed int in C?

前端 未结 5 1240
暖寄归人
暖寄归人 2020-12-08 02:40

Consider these definitions:

int x=5;
int y=-5;
unsigned int z=5;

How are they stored in memory? Can anybody explain the bit representation

5条回答
  •  無奈伤痛
    2020-12-08 03:25

    Here is the very nice link which explains the storage of signed and unsigned INT in C -

    http://answers.yahoo.com/question/index?qid=20090516032239AAzcX1O

    Taken from this above article -

    "process called two's complement is used to transform positive numbers into negative numbers. The side effect of this is that the most significant bit is used to tell the computer if the number is positive or negative. If the most significant bit is a 1, then the number is negative. If it's 0, the number is positive."

提交回复
热议问题