Using Exclamation Marks '!' in C

前端 未结 5 2033
情歌与酒
情歌与酒 2020-12-05 15:15

I have come across a problem involving exclamation marks and integers whilst reading a code in my reference book.

Let us say I have declared an integer variable name

5条回答
  •  情深已故
    2020-12-05 16:02

    In C, !number will evaluate to 1 if number == 0 and to 0 if number != 0. And in C, 1 is true and 0 is false.

    Using an explicit comparison like number == 0 have the same effect but you might find it easier to read.

提交回复
热议问题