Last active
December 16, 2015 19:38
-
-
Save theonewolf/5486167 to your computer and use it in GitHub Desktop.
switch brain teaser
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 <stdio.h> | |
| #include <stdlib.h> | |
| enum option | |
| { | |
| OPT_ONE = 0x01, | |
| OPT_TWO = 0x02, | |
| OPT_THREE = 0x03, | |
| OPT_FOUR = 0x04, | |
| OPT_MAGIC = 0x05 | |
| }; | |
| void test_switch(enum option opt) | |
| { | |
| switch(opt) | |
| { | |
| OPT_ONE: | |
| fprintf(stdout, "OPT_ONE\n"); | |
| break; | |
| OPT_TWO: | |
| fprintf(stdout, "OPT_TWO\n"); | |
| break; | |
| OPT_THREE: | |
| fprintf(stdout, "OPT_THREE\n"); | |
| break; | |
| OPT_FOUR: | |
| fprintf(stdout, "OPT_FOUR\n"); | |
| break; | |
| OPT_MAGIC: | |
| fprintf(stdout, "OPT_MAGIC\n"); | |
| break; | |
| default: | |
| fprintf(stdout, "default, no match found.\n"); | |
| }; | |
| } | |
| int main(int argc, char* argv[]) | |
| { | |
| test_switch(OPT_MAGIC); | |
| return EXIT_SUCCESS; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ZeeD that's the reason why this was linked to as a "brain teaser" not a "compiler teaser." Although many brains are also good enough for this one it seems :-)