Using true and false in C

后端 未结 15 1905
情书的邮戳
情书的邮戳 2020-12-01 01:52

As far as I can see there are 3 ways to use booleans in c

  1. with the bool type, from then using true and false
  2. defining using preprocessor #defin
15条回答
  •  误落风尘
    2020-12-01 02:31

    I used to use the #define because they make code easier to read, and there should be no performances degradation compared to using numbers (0,1) coz' the preprocessor converts the #define into numbers before compilation. Once the application is run preprocessor does not come into the way again because the code is already compiled.

    BTW it should be:

    #define FALSE 0 
    #define TRUE 1
    

    and remember that -1, -2, ... 2, 3, etc. all evaluates to true.

提交回复
热议问题