case ‘m’ :
case ‘M’ : cout<<“Maggi”<<endl;
break;
What does it mean in switch case? I mean how the above statements are going to execute
case ‘m’ :
case ‘M’ : cout<<“Maggi”<<endl;
break;
What does it mean in switch case? I mean how the above statements are going to execute
hello @yashsharma4304
this code will print Maggi when m or M is passed to switch.
let say m is given to switch then
this will execute and becuase break is not used here next statement will execute which is
and it will execute its underlying statement
u will get output as Maggi
and because next statement is break execution will stop.
now let say M is given to switch in such case->
this statement will execute and it will execute it underlying statement which is this->
u will get Maggi in output
and becuase next statement is break execution of switch stop here.
so for both the cases whether u give m or M the switch statement is going to print Maggi
can I write it as:
case ‘M’ or ‘m’ : cout<<"Maggi<<endl;
break;
yeah u can , both will have same working
this will execute and becuase break is not used here next statement will execute which is.
Ok thank you for your great explanation.
