Thursday, 22 August 2013

Why does this switch statement return ZeroHello World instead of just Zero?

Why does this switch statement return ZeroHello World instead of just Zero?

Multi-choice 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" );
}
Options:
One
Zero
Hello World
ZeroHello World
I assumed it would only return Zero. I have played around with what the
int value is and it changed the output but I can't follow what is
happening here.

No comments:

Post a Comment