# Operators

You will have already used Pascal operators such as + and - instinctively as a result of your experience with spreadsheets and mathematical equations. This tutorial covers several types of operator. The definitions and discussion of operator precedence in this general introduction apply to all of the types. As used in these definitions, a symbol means one or more characters representing an operator, value, constant, variable or function.

An operator is a symbol representing an operation (action) to be performed on one or more operands to produce a value.

An operand is an object acted on by an operator and may be a literal value, a declared constant, a variable or the value of another expression.

An expression is a combination of symbols that produces a value when executed. An example of the use of the above terminology is, "In the expression VAT_RATE * Price, the multiplication operator acts on its two operands: the constant VAT_RATE and the variable price."

A subexpression is an expression that is a part of a larger expression.

The precedence of operators refers to the order in which they are carried out when there is more than one operator in an expression. When two operators compete for the same operand, the operator with the higher precedence operates on it first. For operators with the same priority, the order of their actions follows their position in the expression from left to right. You can maximise the precedence of an operator by enclosing its subexpression in brackets. Click on the links below to access sections on mathematical, Boolean and relational operators. Each section gives the precedence of operators of the relevant type and examples of their use. Other types of operator are described briefly below.

The assignment operator, :=, is read as "becomes equal to". As you have seen many times, it simply puts the value of the expression to its right into the variable to its left.

When the operator + has string operands it concatenates (joins) them. For example, the expression Forename + ' ' + Surname evaluates to 'Seb Coe' if we have assigned appropriate values to the variables.

The commonly used set operators are in, +, -, and *. We demonstrate their use in a section of the Sets tutorial.

Note that the same operator symbol can represent different operations depending on the type of operands. For example, the + symbol can represent the addition of numbers, the concatenation of strings or the union of sets.

Programming - a skill for life!

Pascal Programming Tutorials