Difference between char and int when declaring character

前端 未结 5 1630
梦谈多话
梦谈多话 2020-12-07 18:49

I just started learning C and am rather confused over declaring characters using int and char.

I am well aware that any characters are made up of integers in the se

5条回答
  •  孤城傲影
    2020-12-07 19:40

    Usually you should declare characters as char and use int for integers being capable of holding bigger values. On most systems a char occupies a byte which is 8 bits. Depending on your system this char might be signed or unsigned by default, as such it will be able to hold values between 0-255 or -128-127.

    An int might be 32 bits long, but if you really want exactly 32 bits for your integer you should declare it as int32_t or uint32_t instead.

提交回复
热议问题