0
In switch statements we have to take only constant values if yes than why and if no than why not please explain in c ?
4 ответов
+ 2
in java you can use switch with any variable. the case - blocks have to compare to a fix value, because that's exactly what you are trying to do with switch - statements. yet there is no need to use constants here. this concept should be explained in most courses on SoloLearn, because many languages implement it. if you have any specific questions feel free to ask.
+ 2
Yep, the cases have to be compile-time constants: that's because switches aren't if-then-else. The compiler does a binary search for the integer in a static lookup table.
+ 2
sorry I must have read over that
0
Thanks for answering but i am talking about c programing here.