+ 1

why default must be at the end of cases? i changed its place with a case and program worked correct..

11th Jun 2018, 9:22 PM
WPath
WPath - avatar
10 Answers
+ 1
Yes you have right and in comments its make noted from much time but not change its maded
11th Jun 2018, 9:54 PM
KrOW
KrOW - avatar
+ 4
The default option was meant as the last resort where other conditions doesn't meet the criteria, or an option to deal with the unthinkable, "when all else fails take the default path".
11th Jun 2018, 9:36 PM
Ipang
+ 4
the compiler checks all casses and if all of them refused the defult will be executed. no matter where the default is . i read this at book C programming language by Hiedeh Aliabadi.
11th Jun 2018, 10:25 PM
Daniyalmoosafar
Daniyalmoosafar - avatar
+ 2
default case must not be last case... Its usually placed at last for make statements more readable
11th Jun 2018, 9:29 PM
KrOW
KrOW - avatar
+ 2
It doesn't. The compiler turns it into the same thing. Putting the default case at the end is just a style choice.
11th Jun 2018, 9:30 PM
Cailyn Baksh
+ 2
While that sentence is technically wrong, it's not a bad idea to keep it at the end for readability.
11th Jun 2018, 9:38 PM
Cailyn Baksh
+ 1
got it... thank you. but can we tell sololearn to correct this?
11th Jun 2018, 9:39 PM
WPath
WPath - avatar
+ 1
Where SL say this?
11th Jun 2018, 9:43 PM
KrOW
KrOW - avatar
+ 1
Go to Learn part of app, C++ tutorial, Conditionals and Loops, The switch statement, at the bottom of page 7 (The default case) you can see this sentence as a note..
11th Jun 2018, 9:48 PM
WPath
WPath - avatar
0
"The default case must appear at the end of the switch." but this is the sentence in note..
11th Jun 2018, 9:36 PM
WPath
WPath - avatar