What is the difference between false and FALSE?

后端 未结 6 1714
梦谈多话
梦谈多话 2021-02-07 00:22

In many programs, I see statements with the identifiers FALSE and false. Is there any difference between them in the context of C++?

Also in so

6条回答
  •  既然无缘
    2021-02-07 00:32

    FALSE is not defined in the standard. Only false is. true and false are called "Boolean literals", and are keywords in C++.

    FALSE is sometimes defined as a macro. You can't rely on it being present on a standards-compliant environment as it is not part of the standard.

    In other words, the following program is valid C++:

    #include 
    
    #define FALSE 1
    
    int main()
    {
        bool a = false;
        bool b = FALSE;
        std::cout << a << " " << b << std::endl;
        return 0;
    }
    

    and it will print 0 1 as expected. FALSE is not a privileged symbol in any way.

提交回复
热议问题