Operators: Theory

Variables and data types
  • Introduction to loops

    • Assignment operator
    • Expression definition
    • Arithmetic operators
    • Relational operators
    • Logical operators
    • Binary operators
  • Assignment operator

    • Assignment operator (=) is used to assign a value to a variable
    • Usage LHS = RHS;
      • LHS: is a variable used to store the value
      • RHS: is a value or an expression to be evaluated as a value before assigning to the variable
  • Expression

    • An expression is a combination between operands and operators
    • An expression can be evaluated as a value
  • Operators

    • Besides assignment operator, there are more important operators
      • Arithmetic operators: +, -, *, /, %
      • Unary operators: ++, --
      • Logical operators: &&, ||, !
      • Relational operators: >, >=, =, <, <=, !=
      • Bitwise (binary) operators: &, |
  • Arithmetic operators

    • Used to make arithmetic expressions
      • Work with numeric operands
    • Several operators are
      • Add: +
      • Minus: -
      • Multiply: *
      • Division: /
      • Modulus: %
    • Modulus example: 10%3 = 1;
  • Unary operators: ++, --

    • Plus plus operator (++)/minus minus operator (--) is used to increase/decrease the operand by 1
      • E.g., x++ means x = x + 1;
      • E.g., x-- means x = x – 1;
    • The place of these operators matters
  • Logical operators

    • Used to make logical expressions
      • Work with logical operands (true, false)
    • Several operators are
      • AND operator: &&
      • OR operator: ||
      • NOT operator: !
    • TRUTH table
  • Relational/Comparison operators

    • Used to make comparison expression
      • Will produce logical value (true/false)
    • Several operators are
  • Binary/bitwise operators (Advanced)

    • It operates on the operands as binary format
      • It works on a bit at a time
    • Several operators are