Skip to content

Instantly share code, notes, and snippets.

@Phyllostachys
Last active August 29, 2015 14:01
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 Phyllostachys/edda14da01797089c313 to your computer and use it in GitHub Desktop.
Save Phyllostachys/edda14da01797089c313 to your computer and use it in GitHub Desktop.
I was wondering about some of the properties of the ternary operater after discussing them with fellow employees. Apparently, they are very flexible. These seem to work on Coliru: http://coliru.stacked-crooked.com/.
//http://coliru.stacked-crooked.com/a/2011cdffc3009e8d
#include <stdio.h>
int main(void) {
int blah = 5;
blah > 12 ? blah < 10
? blah == 5
? printf("win")
: printf("3")
: printf("2")
: blah > 2 ? blah == 6
? printf("nope\n")
: printf("winner!\n")
: printf("what?\n");
return 0;
}
//http://coliru.stacked-crooked.com/a/e547a6afa6fdb014
#include <cstdio>
int main(void) {
int blah = 5;
blah > 6 ? printf("blah") : ({
printf("hello\n");
printf("there\n");
printf("win\n");
});
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment