Last active
August 29, 2015 14:01
-
-
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/.
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
//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; | |
} |
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
//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