Professional Documents
Culture Documents
PowerPoint Slides To Chapter 03
PowerPoint Slides To Chapter 03
PowerPoint Slides To Chapter 03
Chapter 3
Arithmetic Operators
• Data items that operators act upon are called operands.
Casting
• Means value of an expression can be converted to a
different type, if desired
• The data type associated with the expression itself is not
changed, rather the value of the expression undergoes
type conversion wherever the cast appears, e.g.
((int)(i + f))%4
Let int i = 7 and float f = 8.5, the above expression forces the first
operand to be an integer and therefore is valid and results in
integer remainder 3
Unary Operators
• Operators that act upon a single operand
• Increment and decrement operators can be used as
– Pre-increment operator (++i)
» Here operand will be altered in value before it is utilized
– Post-increment operator (i++)
» Here operator follows the operand and the value will be altered
after before it is utilized
Relational Operators
Logical
Operators
Logical Expression
• Are formed using logical operators
• Represent conditions that are either true or false
• Resulting expression will be an integer (true = 1 and false = 0)
• Act upon operands that are themselves logical expressions
Assignment Operators
• Assigns value of an expression to an identifier, e.g. a = 3
• Assignment operator and equality operator are distinctly
different
• Different assignment operators are used to form
assignment expressions
Assignment Expressions
• Are also referred to as assignment statements
• If two operators in an assignment expression are of
different types then the value of the right-hand operand will
automatically be converted to the type of the identifier on the left
• Multiple assignments are permissible, with assignments
carried out from right to left
Assignment Operators
Conditional Operator is (?:)
Conditional Expression
• Expression using this operator
• Can be written in place of traditional if-else statement
• Frequently appears on the right-hand side of a simple
assignment statement, e.g.
– (I < 0) ? 0 : 100
– The expression (i < 0) is evaluated first
– If i is less than 0, the value of the expression is 0 otherwise it is 100
Operator Precedence
• Is the order of evaluation
• Operators with high precedence are evaluated before
operators with low precedence
Associativity of Operators
• Is the order in which consecutive operations within the
same precedence group are carried out
• Is from left to right
• Natural precedence can be altered through the use of
parentheses
Operator Precedence
Library Functions
• Carry out various commonly used operations or
calculations
• Accessed simply by writing the function name, followed
by a list of arguments that represent information being
passed to the function