+ 1

can we use switch with char and string

8th Feb 2017, 4:39 PM
kanishkaditya shukla
kanishkaditya shukla - avatar
4 Answers
+ 3
Java: Yes, you can use char and String. Switch statement with String was implemented in Java7.
8th Feb 2017, 4:48 PM
Tashi N
Tashi N - avatar
+ 1
i was asking for c++ but thanks for your answer. if you know about c++ pls help me with it.
8th Feb 2017, 4:53 PM
kanishkaditya shukla
kanishkaditya shukla - avatar
+ 1
You can't use a string with a switch statement in c++, but you can use a char. A string in c++ is basically a char array and attempting to use a string would be like trying to switch on an array. You could get a char from a string and switch on that just fine though. Really AFAIK you can only switch on an integer type (int), but since char is basically an int it works also.
8th Feb 2017, 5:46 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
thanku very much
9th Feb 2017, 4:09 AM
kanishkaditya shukla
kanishkaditya shukla - avatar