answersLogoWhite

0

There is no such thing as a fall through statement in C++. You are probably referring to switch statement fall through. With a switch statement, execution begins at the case label that matches the evaluation of the controlling expression and falls through all subsequent statements and case labels until a break statement is encountered (break, return or goto) or the end of the switch statement is reached. For example:

switch (x) {

case 0:

// When x is 0, execution begins at this point.

// ...

break; // We jump to the end of the switch at this point (exiting the switch statement).

case 1:

// When x is 1, execution begins at this point.

// ...

// There is no break statement, so execution falls through to case 2.

case 2:

// When x is 2, execution begins at this point, unless we fell through from case 1.

// ...

// There is no break statement, so execution falls through to case 3.

case 3:

// When x is 4, execution begins at this point unless we fell through from case 3.

// ... // There is no break statement, so execution falls through to the default case.

default:

// Execution begins at this point for all values x other than 0, 1, 2, 3 and 4 (all other cases)

// unless we fell through from case 3.

// Note that the default case needn't be the last case in a switch.

// ...

// Again, no break statement so we fall through to case 4.

case 4:

// When x is 4, execution begins at this point unless we fell through from the default case.

// ...

// No break is required in the final case...

} // ...we simply fall off the end of the statement, just as we would with all compound statements.

In the above example, case 0 behaves in the usual way, while all others fall through to the end. The value of x simply determines at which point in the switch execution starts from. The value 1 executes every statement other than those defined by case 0, while the value 2 executes every statement other than those specific to case 0 and 1.

Note that if every case has a break statement to prevent fall through then the order of the cases is immaterial. However, when using fall through, the order of the case labels is vital. Break statements may be placed anywhere in the switch, but are not required at the end of the final case.

User Avatar

Wiki User

9y ago

What else can I help you with?

Related Questions

Which statement is not frequently used in C plus plus?

The goto statement.


What is the deffernce of the switch statement and the if statement in c plus plus?

If statement is single selection statement,whereas the switch statement is multiple selective.


Basic control structure available in c plus plus?

The basic control structure in C++ is the if statement.


A c plus plus statement that invokes a function is known as?

...a function call.


Which statement in C plus plus is used to implement a decision structure in its simplest form-that of choosing between two alternatives?

if (condition) statement else statement;


What is the function of visual c plus plus switch condition?

The switch / case statement.


What is the character used at the end of executable statements in C plus plus?

The semi-colon converts a C++ expression into a statement.


How can write the name in c plus plus language without using cout statement?

I believe, you can use C-function - printf().


How can you print your name in c or c plus plus with out using semi column?

You can not print your name in C without a semi colon because according to the rules of C every statement should end with a semi colon.In fact without the semi colon it fails to be a valid C statement.


Can you write plus at end of c statement?

No. That would be a syntax error. Only a right semicolon (;) can go at the end of a statement.


What statement describes the function c equals 5g plus 8?

It is an equation in two variables, c and g.


What are the conditional statement of turbo c plus plus dos based?

Statements that check an expression then may or may not execute a statement or group of statements depending on the result of the condition.