int main(void)
{
int a = 4;
int b = 45;
switch(a)
{
default:
b = 5;
cout << “Mouse\n”;
case 1:
b = 25;
cout << “Dog\n”;
case 2:
b = 12;
cout << “Cat\n”;
case 3:
b = 24;
cout << “Lemur\n”;
}
cout << b << endl;
b = 12;
a = 6;
double c = 4.5;
c = (b > a ? 1.2 : a+b);
cout << c << endl;
if(b)
cout << “Yes\n”;
else
cout << “No\n”;
return 0;
}
The output (of the first part, which is what I'm concerned about) is:
Mouse
Dog
Cat
Lemur
Now... we initialize a to be 4... so since there is no "case 4:" statement, I'd assume the program only jumps to the default statement and prints out "Mouse". Why does it print out the other statements?
Question
Ravager
int main(void) { int a = 4; int b = 45; switch(a) { default: b = 5; cout << “Mouse\n”; case 1: b = 25; cout << “Dog\n”; case 2: b = 12; cout << “Cat\n”; case 3: b = 24; cout << “Lemur\n”; } cout << b << endl; b = 12; a = 6; double c = 4.5; c = (b > a ? 1.2 : a+b); cout << c << endl; if(b) cout << “Yes\n”; else cout << “No\n”; return 0; }The output (of the first part, which is what I'm concerned about) is:
Mouse
Dog
Cat
Lemur
Now... we initialize a to be 4... so since there is no "case 4:" statement, I'd assume the program only jumps to the default statement and prints out "Mouse". Why does it print out the other statements?
Link to comment
Share on other sites
1 answer to this question
Recommended Posts