Skip to content

Instantly share code, notes, and snippets.

@KushalP
Created April 7, 2011 17:49
Show Gist options
  • Save KushalP/908305 to your computer and use it in GitHub Desktop.
Save KushalP/908305 to your computer and use it in GitHub Desktop.
This always prints 'none'
#include <stdio.h>
const char *example(int num) {
const char *str;
switch (num) {
case 1:
str = "one";
case 2:
str = "two";
case 3:
str = "three";
default:
str = "none";
}
return str;
}
int main(int argc, char **argv) {
printf("%s\n", example(2));
return 0;
}
@OrangeTide
Copy link

you need break;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment