Instructions and operators

Expressions

  • Simple expressions:

    • Variable: m

    • Constant: 4

  • Composed expressions:

    • Arithmetic operators precedence

      1. Post-increase/Post-decrease ➡️ e.g.: i++, i--

      2. Pre-increase/Pre-decrease ➡️ e.g.: ++i, --i

      3. * / % ➡️ e.g.: i*2, i/2, i%2

      4. + - ➡️ e.g.: i+1, i-1

      5. = ➡️ e.g.: i=1

      These operators have Side Effect on the operands (they can modify their values).

    • Relational

      • Comparison ➡️ < <= > >=

      • Equality ➡️ =

      • Inequality ➡️ !=

    • Logical

      • NOT ➡️ !

      • OR ➡️ ||

      • AND ➡️ &&

      These operators have Lazy evalutation:

      • expr1 && expr2: if expr1 is false, expr2 is not evaluated ➡️ returns false

      • expr1 || expr2: if expr1 is true, expr2 is not evaluated ➡️ returns true

    • Bitwise applicable only to two data types (int and char) and all the other derivated types (short int, unsigned int, long int, unsigned char)

Operator
Operator name
Notes

~x

Bitwise Complement

x ^ y

AND

x | y

OR

x ^ y

XOR

x >> n

Right SHIFT (by n bits)

Add 1s on the left

x << n

Left SHIFT (by n bits)

Add 0s on the right

L-value

Modifiable entities and variable:

  • on the left of the assignment operator (=)

  • they should not be:

    • constants

    • results of expressions (m+n = 0;)

Instruction (Expression Statement)

Expression with Side Effect followed by ;.

Example: The following expression is not read by the compiler (the same happens for the comments):

i+4;

because the previous instruction has not side effect.

Last updated