c - switch case isn't true than also its executing case which is inside the failed one -
#include<stdio.h> int main() { switch(2) { case 1: if(1) { case 2: printf("hello\n"); }; } return 0; } output = hello i'm passing 2 in switch case 1 not true enters , executes code inside case 2. how come enters case 1? thanks.
after switch(2), jump case 2 label. fact within if block contained within case 1 irrelevant. case 2: functions no differently goto label, jump wherever is. not true case 1 somehow being entered.
to clarify, indented looks thus:
#include<stdio.h> int main() { switch(2) { case 1: if(1) { case 2: printf("hello\n"); } ; } return 0; }
Comments
Post a Comment