+ 5
Need a little help with switch
This is my program: #include <stdio.h> int main() { int i = 0; switch (i) { case '0': printf("IXEL"); break; case '1': printf("FOR"); break; default: printf("TRAINING"); } return 0; } shouldn't asnwer be IXEL?? answer is TRAINING Why???
4 ответов
+ 4
It’s because of data types. ‘0’ and 0 are not the same thing, ‘0’ means a character.
Here is the corrected code:
#include <stdio.h>
int main()
{
int i = 0;
switch (i)
{
case 0: printf("IXEL");
break;
case 1: printf("FOR");
break;
default: printf("TRAINING");
}
return 0;
}
+ 1
'0' is a char data type so to correct it you should write case 0: and case 1: