Hello, I need help in understanding the switch statement in C.
Why does the following code either display 'RED' or 'WHITE' when I enter
'r' or 'w'?
#include <stdio.h>
#include <ctype.h>
int main(void)
{
char choice;
switch (choice = getchar()) {
case 'r':
case 'R':
printf("RED");
break;
case 'w':
case 'W':
printf("WHITE");
break;
}
}
Should it not only output 'RED' or 'WHITE' when you enter 'R' or 'W'?
Thanks,
--ayyaz
