I found an interesting Programing question :
What will be the values of a,b,c,f after executing this programe ?
int i=0,a=0,b=0,c=0,f=0;
while(i<=5){
switch(i++){
case 1:++a;
case 2:++b;
break;
case 3:
case 4:++c;a++;b++;
break;
default:++f;
}
}
I thought that the values
a=2 , b=2 , c=2 and f=2 but
when i executed this programe i got a = 3, b = 4, c = 2 and f = 2.
I understood how c and f got it values 2 but how come a=3 and b=4.
(As per the syntax ++a and a++ are different as ++a updates the value and then uses it where as a++ uses the value and then updates it )
Can anyone explain how a and b got its values as 3 and 4.
UPDATE:
Hey my doubt is : In i++ the intial value is 0 and not 1. But then how case 4 => a=3
It should be a=2 and should incriment the value if there was any updation of 'a' in case 5 (which is not true)as i haven't given any substitution like a=a++.
Any Help appreciated.