+ 1

Switch (string)

can you have a switch having a string as it's value

18th Apr 2017, 7:26 PM
samuel manuel
samuel manuel - avatar
3 Respostas
0
Of course, you can do this: switch (<string variable>) { case "anything": <statement> } At least in java and c i believe you can.
18th Apr 2017, 7:51 PM
José Pereira
José Pereira - avatar
0
i think it is not possible in C the only types you can use are int and char
18th Apr 2017, 8:03 PM
Walid Boudebouda
Walid Boudebouda - avatar
0
You're right, forgot about that. But tecnically a char pointer is a string since it's kept on a read-only zone in the memory so perhaps it's possible.
18th Apr 2017, 8:07 PM
José Pereira
José Pereira - avatar