+ 2
Switch cases should be an integer?
GNU/GCC debugger print "switch not an integer".
5 Respostas
+ 2
Integer is allowed
char also allowed
+ 2
@Pamir You can't use strings or floats in switch statements.
+ 2
I want use switch for strings too
+ 1
Jop, only integers (int, long, char unsigned int etc allowed). Or enums... but they are basically integer.
0
use switch-case like:
-psuedo code-
int c; //it is for switch controller
switch(c){ //switch using
case 1:{ //case 1 for ( if (c == 1) )
//operations
break;
}
case 2:{ //case 2 for ( if (c == 2) )
//operations
break;
}
...//so goes-on
default:{ //case default for if none of the cases match
//operations
break;
}
}
edit 1:
you can use:
-integers,
-char,
-string,
-float,
-basically every primitive data types.
edit 2:
@Cohen is right, i was wrong. I tried string, float, double and it gives me error. Still you can use integer and char.