Skip to content

Instantly share code, notes, and snippets.

@andermoran
Last active October 2, 2019 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andermoran/9a314c5cabaa4665b169fe7fa69e63b0 to your computer and use it in GitHub Desktop.
Save andermoran/9a314c5cabaa4665b169fe7fa69e63b0 to your computer and use it in GitHub Desktop.
Ways to evaluate boolean expressions in c++
#include <iostream>
#include <sstream>
using namespace std;
int main(int argc, char *argv[]) {
bool b = true;
// High school level
if (true) {
cout << "simple conditional" << endl;
}
// Freshman in college level
if (b == true) {
cout << "intermediate conditional" << endl;
}
// PhD level
if (strncmp ((b ? "true" : "false"),"true",5) == 0) {
cout << "advanced conditional" << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment