in Programming edited by
176 views
1 vote
1 vote

What is the output of the following program?

#include <stdio.h>
int main()
{
int a = 0;
switch(a)
{
default:
a = 4;
case 6:
a--;
case 5:
a = a+1;

case 1:
 a = a-1;
}
printf("%d \n",a);
return 0;
}
in Programming edited by
by
176 views

1 Answer

1 vote
1 vote
Best answer

when the value of a matches with none of the cases, then the default value of 4 gets assigned to a and a "fallthrough" happens since there is no "break" statement. Hence, all the expressions involving a gets executed and the resulting value is 3

selected by
Answer:

Related questions