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; }
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
64.3k questions
77.9k answers
244k comments
80.0k users