c - what is output ? gcc output is 0. please explain? -
this question has answer here:
- doubts in using switch statement in c 5 answers
gcc compiler output 0. why? shouldn't 3?
int main() { f(3); return 0; } int f(int t) { int c; switch(t) { case 2: c=2; case 3: c=3; case 4: c=4; case 5: c=5; default: c=0; } printf("%d",c); }
because missing break;
statement in each of cases. leads control falling through following case statements , default
case.
Comments
Post a Comment