thinkingincode.ninja [Dark]

Operators

Operators are used to compare, manipulate, or assign data and values. I am covering operators before variables because I think it makes a little bit more sense in this order. For the purposes of understanding operators, all you need to know about variables is that a variable associates a name with a value in memory. The most common operators, and what they do, are listed below. Unary operators operate on a single value, binary operators operate on two values; unless otherwise specified, all operators are binary. For reference, binary operators follow the template LEFT operator RIGHT, while unary operators follow the template operator RIGHT. Also, if something is said to "evaluate to true if {some condition}", then when that condition is not met, it will evaluate to false.

The following are special unary operators, following the template operator VARIABLE or VARIABLE operator. If the operator comes before the variable, it is a prefix operator; if it comes after, it is a postfix operator. A prefix operator will perform the operation and evaluate to the new value the variable has, while a postfix operator will perform the operation but evaluate to the value the variable had before performing the operation. All examples below start with the variable a having the value 10.

Not every language (such as assembly) uses these operators, but most do. Some languages will use := instead of = as the assignment operator.

It is also worth noting that in several languages, anything which is zero is false, and anything non-zero is true, when viewed in a boolean context.

Suggested next reading: Data structures and variables