I've been learning how to use C++ for a week now, but I can't seem to figure out, why something is that. The tutorials have knowledge testers, but I can't figure out why the last question is what it is. Here is the question:
What is the result of the following code?
int x=0;
switch(x)
{
case 1: printf( "One" );
case 0: printf( "Zero" );
case 2: printf( "Hello World" );
}
the answer is "ZeroHello World",
but why? I don't get it, can someone help me please?
It's actually more like, depending on the initial value, you jump to a certain position in the switch statement. Once you are inside the switch statement, no further checks will be performed. All code following the entry point will be executed until you either hit a break or the end of the switch block.