LECTURE 04 Conditional Expressions Com Prog 1
LECTURE 04 Conditional Expressions Com Prog 1
AND
EXPRESSIONS
Handout 04 - Midterm(Com Prog 1)
Agenda
Operators Expressions
Arithmetic Operators Arithmetic Expressions
Assignment Operators Assignment Expressions
Unary Operators Relational Expressions
Comparison Operators Logical Expressions
Shift Operator Conditional Expressions
Bitwise Operator
Logical Operator
Conditional Operator
Order of Precedence of Operators
OPERATORS
For the right shift, the bits of the left operand are shifted right. Using 𝑥 = 9 ≫ 2, the
result becomes 2:
For the left shift, the bits of the left operand are shifted left. Using 𝑥 = 9 ≪ 2, the
result becomes 40:
Bitwise Operators
Compared to previous operators, bitwise operators
perform operations bit-by-bit. These operators can be
applied to byte, int, short, long, and char data types.
Logical Operators
These are used to combine the results of Boolean
expressions. These operators share a likeness with
bitwise operators, but logical operators are limited to
Boolean expressions only.
Conditional Operator
This operator is used to control the flow of the program.
The ternary operator is used mainly in loop
statements.
Order of Precedence of Operators
Order of Precedence shows the hierarchy wherein an operation with
high precedence is performed before the others. The table shows
those with the same level of precedence are listed in the same row.
EXPRESSIONS
An expression is a combination of variables, constants, literals, and
operators to produce a single value. A simple 23 + 16 and x = -82 are
considered expressions.
Assignment Expression
It is an expression that involves assigning a value to a variable. For
example:
Relational Expression
It is an expression that compares values using relational operators.
For example:
Logical Expression
It is an expression involving logical operators. For example:
Conditional Expression
It is an expression involving the use of the ternary operator (?:) to
assign a value based on a condition. For example:
THANK
YOU