C Operators Notes
C Operators Notes
RECORDED LECTURE 4 -
OPERATORS
Operators
Assignment Operator
Symbol: ‘=’
Arithmetic Operator
Multiplication - ‘*’
Division - ‘/’
Addition - ‘+’
Subtraction - ‘-’
Modulus - ‘%’
Relational Operator
Less than - ‘<’
Equal to - ‘==’
Logical Operator
Truth Table: Result is true if and only if all expressions are true
T T T
T F F
F T F
F F F
or - ‘||’
T T T
T F T
F T T
F F F
not - ‘!’
! Exp Result
T F
F T
Increment Operator
Symbol: ‘++’
Adds 1
If it is placed before the variable, the operation takes place before any
other
If it is placed after the variable, the operation takes place after others
Decrement Operator
Symbol: ‘—’
Subtracts 1
If it is placed before the variable, the operation takes place before any
other
If it is placed after the variable, the operation takes place after others
Examples:
1. —A where A = 5 → A=?=4
2. A— where A = 5 → A=?=4
Combined Operators
*=
/=
+=
-=
%=
An equation in the form of: ‘<var> = <var> <arithmetic operator> <expr>’ can
be simplified using the format: <var> <arithmetic operator> = <expr>
1. X = X*Y → X*=Y
2. X = Y*X → X*=Y
3. X = X/(Y+2) → X/=(Y+2)
4. X = X+3 → X+=3
5. X = X-1 → X-=1 or X—