Using true and false in C

后端 未结 15 1875
情书的邮戳
情书的邮戳 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:38

    I prefer to use

    #define FALSE (0!=0) 
    #define TRUE  (0==0)
    

    or directly in the code

    if (flag == (0==0)) { ... }
    

    The compiler will take care of that. I use a lot of languages and having to remember that FALSE is 0 bothers me a lot; but if I have to, I usually think about that string loop

    do { ... } while (*ptr);
    

    and that leads me to see that FALSE is 0

提交回复
热议问题