Code: int i=3; switch(i) { default: printf("zero"); break; case 1: printf("one"); break; case 2: printf("two"); break; case 3: printf("three"); break; } the result obtained for this code is three.. what is the reason.. i think zero might be the result since the default statement comes before the other case statement.. so a soon as it enters the switch it might execute the statements within default and exit the switch on seeing the break statement ... therefore zero will be the output... but it is not why...????? what happens exactly during the execution???? help me friends!!
Look, the first thing you need to do is read the "Before you make a query" thread. It tells you to use code tags to retain the formatting of your code. Failing to do so is being rude to the people from whom you are seeking free help. It does not enter the default case because i matches one of the cases, namely 3. It is working as it should. This is three "doubt" posts. You need to read a dam' book, son.
Priya, you have declared that int i = 3; therefore the c compiler will take i =3 ; if you say int i ; or int i = 0; then it will go to default .
default statement can be placed anywhere in the loop. But it will be executed only when all the cases didn't match.