In c, in bool, true == 1 and false == 0?

前端 未结 2 1609
醉梦人生
醉梦人生 2021-02-14 19:07

Just to clarify I found similar answer but for C++, I\'m kinda new to coding so I\'m not sure whether it applies to C as well.

相关标签:
2条回答
  • 2021-02-14 19:41

    More accurately anything that is not 0 is true.

    So 1 is true, but so is 2, 3 ... etc.

    0 讨论(0)
  • 2021-02-14 19:54

    You neglected to say which version of C you are concerned about. Let's assume it's this one:

    http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf

    As you can see by reading the specification, the standard definitions of true and false are 1 and 0, yes.

    If your question is about a different version of C, or about non-standard definitions for true and false, then ask a more specific question.

    0 讨论(0)
提交回复
热议问题