Last active
May 7, 2016 23:00
-
-
Save complxalgorithm/791cdef0da39c191e522245bfc97fe14 to your computer and use it in GitHub Desktop.
Displays short circuit evaluation in C++.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
bool a(bool in) | |
{ | |
cout << "a" << endl; | |
return in; | |
} | |
bool b(bool in) | |
{ | |
cout << "b" << endl; | |
return in; | |
} | |
void test(bool i, bool j) { | |
cout << boolalpha << i << " and " << j << " = " << (a(i) && b(j)) << endl; | |
cout << boolalpha << i << " or " << j << " = " << (a(i) || b(j)) << endl; | |
} | |
int main() | |
{ | |
test(false, false); | |
test(false, true); | |
test(true, false); | |
test(true, true); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment