Operators and Expression
Operators and Expression
Chapter 3:Operators and Expressions| SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2006 | Last Updated: July 2006 Slide 1
(Operators & Expression)
Statements,
Arithmetic
Operators &
Operators
Operands
Relational
Logical Operators
Operators
Assignment
Operators
Statement
• Statements are elements in a program which
(usually) performing with suitable object
– e.g. below is a statement of calling input value
Arithmetic operator: −
◼ This operator has two meanings:
◼ subtraction operator (binary) e.g. 31 - 2
Arithmetic operator: %
• The modulus (remainder) operator.
• It computes the remainder after the first operand is divided by
the second
e.g. 5 % 2 is 1, 6 % 2 is 0
Relational operators
• These perform comparisons and the result is what
is called a boolean: a value TRUE or FALSE
• FALSE is represented by 0; anything else is TRUE
• The relational operators are:
– < (less than)
– <= (less than or equal to)
– > (greater than)
– >= (greater than or equal to)
– == (equal to)
– != (not equal to)
Logical operators
(also called Boolean operators)
Is it 17 - (8 * 2)
or (17 - 8) * 2 ?
* / %
+ –
Associativity: execute left-to-right (except
< <= >= > for = and unary – )
== !=
and
or
lower precedence
=
Example: Left associativity
3*8/4%4*5
Example: Right associativity
a += b *= c-=5
Precedence & associativity
• Examples:
Z = 10 + 9 * ((8 + 7) % 6) + 5 * 4 % 3 *2 + 1 ?