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

前端 未结 3 692
青春惊慌失措
青春惊慌失措 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:48

    If your int or unsigned int is 32-bits, neither can store the value 4294967296 since this is 2**32 which would require a 64-bit type.

    Even uint32_t can only store the max value 2**32 - 1 so your value is just 1 out of range.

    But int32_t can store the max positive value 2**31 - 1 so the signed type is even further off.

提交回复
热议问题