Category: Conditional Statements in C Plus Plus

Interested in learning C Programming? Click here...

Switch Statement in Cpp 2

Switch Statement in C++

The switch statement is a special multiway decision maker that tests whether an expression matches one of the number of constant values accordingly. switch statement allows the user to choose a statement or a group of statements among several alternatives. The switch statement is useful when a variable is compared with different constants, and in case it is equal to a constant, a set of statements would be executed. The general form of the switch statement is as follows:

In this general form: 1) The expression, whose value is being compared, may be any valid expression but not a...

if else statement in c++ 2

If-else Statement in C++

if-else statement if statement is most commonly used with the following format:

where else part is optional. In this case, either of the two statements are executed depending upon the value of the expression. If the expression has a non-zero value (i.e., if the expression is true), then statement1 will be executed. Otherwise (i.e., if expression is false), statement2 will be executed. Example: Given here is a program which reads a number and then prints whether the given number is even or odd. Note: If we divide a number by 2 and if the remainder is 0 then the...

If Statement in Cpp 1

If Statement in C++

if statement: The if statement is used to express the conditional expressions. If the given condition is true then it will execute the statements otherwise it will execute the optional statements. The basic simple structure of the if statement is shown below:

The expression must be placed in round brackets as shown above. In this form, the set of statements would be executed only if the expression has a non-zero value (i.e., if expression is true). If the expression has a value zero (i.e., if expression is false), then the set of statements would be ignored by C++ compiler....