What is the difference between (char)0 and '\0'? in C

前端 未结 4 844
梦谈多话
梦谈多话 2020-12-24 12:23

What is the difference between using (char)0 and \'\\0\' to denote the terminating null character in a character array?

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-24 12:43

    They're both a 0, but (char) 0 is a char, while '\0' is (unintuitively) an int. This type difference should not usually affect your program if the value is 0.

    I prefer '\0', since that is the constant intended for that.

提交回复
热议问题