In control structure case what is the purpose of default in C++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 7

In control structure case what is the purpose of default in C++

17th Mar 2019, 8:03 PM
Sally(Codder)
Sally(Codder) - avatar
4 Answers
+ 8
My answer is the keyword gives the switch.. Case construct a way to take an action if the value of the switch variable doesnot match with any of the case construct, no break statement is necessary after default case, since the control is already at the end of switch.. Case construct. The default is optional incase of switch.. Case statement
17th Mar 2019, 8:06 PM
Sally(Codder)
Sally(Codder) - avatar
+ 9
default in both C and CPP allows for code execution when all the above cases/conditioned are false/ not satisfied.
9th Apr 2019, 6:39 PM
OkomoJacob
OkomoJacob - avatar
+ 8
Oh you like your own answer best?
19th Mar 2019, 12:30 AM
Sonic
Sonic - avatar
+ 2
If all other cases didn't match do something else Example You made calculator with switch case for operator Somebody entered $, which fails all operators so you covert it to + (or any other) in default
17th Mar 2019, 8:05 PM
Elva
Elva - avatar