Is there an Non-Short circuited logical “and” in C++?

前端 未结 7 2115
栀梦
栀梦 2020-12-06 08:49

tl;dr: Is there a non-short circuit logical AND in C++ (similar to &&)?

I\'ve got 2 functions that I want to call, and use the return values to figure out th

相关标签:
7条回答
  • 2020-12-06 09:52

    Yes there are built in operators for doing this. + does a non short circuiting OR and * does an AND.

    #include <iostream>
    using namespace std;
    
    void print(bool b)
    {
        cout << boolalpha << b << endl;
    }
    
    int main() 
    {
        print(true + false);
        print(true * false);
    }
    

    Output:

    true

    false

    0 讨论(0)
提交回复
热议问题