Using boolean values in C

前端 未结 18 2058
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 12:51

C doesn\'t have any built-in boolean types. What\'s the best way to use them in C?

18条回答
  •  旧时难觅i
    2020-11-22 13:08

    You can simply use the #define directive as follows:

    #define TRUE 1
    #define FALSE 0
    #define NOT(arg) (arg == TRUE)? FALSE : TRUE
    typedef int bool;
    

    And use as follows:

    bool isVisible = FALSE;
    bool isWorking = TRUE;
    isVisible = NOT(isVisible);
    

    and so on

提交回复
热议问题