Cant i store 4294967295 in unsigned int ? Int is 4 bytes on my machine

前端 未结 3 695
青春惊慌失措
青春惊慌失措 2021-01-29 10:43

Why am i getting 0 ?? And compiler warning:

format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘long unsigned int’

3条回答
  •  离开以前
    2021-01-29 11:30

    Assuming an int is 4 bytes and you have 8 bit bytes, then int is 32 bits wide. Subsequently a signed int (if negatives are represented in 2's complement) has a range of -2147483648 to 2147483647 while unsigned int has a range of 0 to 4294967295.

    The value 4294967296 in binary is 1 00000000 00000000 00000000 00000000. This is 33 bits. So 4294967296 is too big for this type.

提交回复
热议问题