Lecture-5-C Control Statement
Lecture-5-C Control Statement
C programming language
assumes any non-
zero and non-null values
as true, and if it is
either zero or null, then it
is assumed as false value.
Types of control statements
C language provides following types of decision making
statements. Click the following links to check their detail.
Statement Description
1. if statement An if statement consists of a Boolean expression
followed by one or more statements.
2. if...else statement An if statement can be followed by an optional else
statement, which executes when the Boolean expression
is false.
3. nested if statements You can use one if or else if statement inside
another if or else if statement(s).
4. if...else if..else An if statement can be followed by an optional else
statement if...else statement, which is very useful to test various
conditions using single if...else if statement.
5. switch case-statement A switch statement allows a variable to be tested for
equality against a list of values.
6. nested switch You can use one switch statement inside another switch
statements statement(s).
7. Ternary operator ? : ?: can be used to replace if...else statements
Where Exp1, Exp2, and Exp3 are expressions. Notice the use
and placement of the colon.
The ?: is called a ternary operator because it requires three
operands.
The value of a ? expression is determined like this:
Output: