Using boolean values in C

前端 未结 18 2047
被撕碎了的回忆
被撕碎了的回忆 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条回答
  •  难免孤独
    2020-11-22 13:05

    Nowadays C99 supports boolean types but you need to #include .

    Example:

    #include 
    
    int main() 
    { 
        bool arr[2] = {true, false}; 
    
        printf("%d\n", arr[0] && arr[1]);
        printf("%d\n", arr[0] || arr[1]);
    
        return 0; 
    } 
    

    Output:

    0
    1
    

提交回复
热议问题