Computer Science, asked by prameelaanil77, 9 months ago

the purpose of default statement in switch statement​

Answers

Answered by Zisha7
6

Answer:

Switch case statements are used to execute only specific case statements based on the switch expression. If switch expression does not match with any case, default statements are executed by the program.

Answered by msrishti0104
0

Answer:

The purpose of the default in the switch case is to provide an option in case the conditions specified to trigger the execution of code within the other options does not occur so that the program will not crash.

For example lets say you have a case if the number 1 is entered by the user print ‘one’ to a display, and if number 2 print ‘two’ to the display. If the user enters any other number of which their is an infinite amount what would occur? Without the default statement the program would crash or make the user annoyed because they do not get any feedback from the program.

switch( x )

{

case 1 :

. . .

( print 'one')

. . .

case 2 :

. . .

( print 'two')

. . .

default:

(print ' invalid number entered')

}

If this answer was helpful, please mark it as the brainliest:)

Explanation:

Similar questions