Operating on variables
Operators apply simple operations such as addition and multiplication to operands such as variables and literal values. They usually return a new value that is the result of the operation that can be assigned to a variable.
Most operators are binary, meaning that they work on two operands, as shown in the following pseudocode:
var resultOfOperation = firstOperand operator secondOperand;
Some operators are unary, meaning they work on a single operand, and can apply before or after the operand, as shown in the following pseudocode:
var resultOfOperation = onlyOperand operator; var resultOfOperation2 = operator onlyOperand;
Examples of unary operators include incrementors and retrieving a type or its size in bytes, as shown in the following code:
int x = 5; int incrementedByOne = x++; int incrementedByOneAgain = ++x; Type theTypeOfAnInteger = typeof(int); int howManyBytesInAnInteger = sizeof(int);
A ternary operator works on three operands...