Professional Documents
Culture Documents
4 CS1PR16 Performing Operations
4 CS1PR16 Performing Operations
Arithmetic operations:
Addition +
Subtraction -
Multiplication *
Division /
Modulus %
Precedence – mathematical rules apply here: Parenthesis -> division- > multiplication -> addition ->
subtraction.
Integer and floating points operations may give different results. Floating points should be used it you
want anything with decimal points.
Logical operations – they are used with values true/false. In C, 0 represents false, any non zero integer
represents true.
Logical AND &&
Logical OR ||
Logical inversion !
Assignment operator - "=" means becomes, not equals. It evaluates the expression on its right hand side
and assigns its value to the variable on the left hand side. == is used to test for equality.
Shorthand assignment operators:
o x = x + 5 can be written as x += 5.
o x = x – 3 can be written as x -= 3.
o x = x * 4 becomes x*=4.
o It is the same with /= and %=.