Switch case statement and default statement in c | Switch case default statement behavior

How to act default statement in the switch case
int sw=5;
int y=2;
Char op=’*’;
switch(op)
{
default:sw+=1;
case ‘+’ :sw+=y;
case ‘-‘:sw-=y;
}
Debugging Answer:
6
Debugging Solution:
Switch case statement it will go to default statement because
It does not match with any other statement. so in the default statement
It will increase there sw value by one

Post a Comment

0 Comments