Skip to content

Instantly share code, notes, and snippets.

@complxalgorithm
Last active May 7, 2016 23:00
Show Gist options
  • Save complxalgorithm/791cdef0da39c191e522245bfc97fe14 to your computer and use it in GitHub Desktop.
Save complxalgorithm/791cdef0da39c191e522245bfc97fe14 to your computer and use it in GitHub Desktop.
Displays short circuit evaluation in C++.
#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