To all those who use C++ and to the creator of C++ . I want to ask a question . What is the use of the default case in a switch statement ?
It is actually to be executed when no case is satisfied , but it is executed even when there is no break; after the last case and the last case is satisfied. Why is it so ?
switch(i) case 1 : cout<<"ONE"; break; case 2 : cout<<"TWO"; default :cout<<"NONE"; }
In this case , if the input is 2 , it should output only TWO , but it will OUTPUT TWO NONE according to the C++ compiler. This is wrong with respect to the purpose of the default statement .