In: Computer Science
consider execution of the following switch statement:
int Enter = 10;
cin >> Enter;
switch (Enter)
{
case 1: Enter = -4;
case 2: Enter = -6;
case 4: break;
case 6: Enter = -8;
break;
default: Enter = -1;
}
What would the value of Enter be after execution of this code if the value read for Enter were 4?
-4,-6,-8 or none
/*
As we are giving 4 as input to Enter value Enter is assigned with 4 so at present, the value of Enter is 4
In switch case, if Enter is 4 we are just breaking the switch so Enter is still 4.
*/
//CODE
#include <iostream>
using namespace std;
int main()
{
int Enter = 10;
cin >> Enter;
switch (Enter)
{
case 1: Enter = -4;
case 2: Enter = -6;
case 4: break;
case 6: Enter = -8;
break;
default: Enter = -1;
}
cout << "Enter : " << Enter;
return 0;
}
//OUTPUT