What is the output of the following code a is 4 and i is 10
What is the output of the following code a is \'4\' and i is 10? a is \'1\' and i is 40? a is \'A\' and i is 1? switch(a){case \'1\':: i++; case \'2\': --i; case \'3\':: i+=2; break; case \'4\': i=3; case \'5\':: ++i; case \'6\':: i++; break; default: i-=3;} cout
Solution
Answer:
a. a=4 and i=10:
As a=4 case 4 (i=3;) will be executed. Therefore Output is i : 3.
b. a=1 and i=40:
As a=1 case 1 (i++;) will be executed. Therefore Output is i : 41.
c. a=A and i=1:
As a=A default (i -=3;) will be executed. Therefore Output is i : -2 (minus 2).
