0

Explain about switch in c program

6th May 2022, 11:46 AM
Narasimharao Narasimharao
1 ответ
+ 2
switch is just an alternative to nested if-else to test values: switch (x) { case 1: //do stuff 1 break; case 2: //do stuff 2 break; case 3: //do stuff 3 break; default: //do default stuff } is the same as if (x == 1) { //do stuff 1 } else if (x == 2) { //do stuff 2 } else if (x == 3) { //do stuff 3 } else { //do default stuff }
6th May 2022, 12:41 PM
OrHy3
OrHy3 - avatar