Operating on variables
Operators apply simple operations such as addition and multiplication to operands such as variables and literal values. Operators return a new value that is the result of the operation and can be assigned to a variable, and they can also affect the operands.
Understanding binary operators
Most operators are binary, meaning that they work on two operands, as shown in the following pseudocode:
var resultOfOperation = firstOperand operator secondOperand;
Examples of binary operators include adding and multiplying, as shown in the following code:
int x = 5;
int y = 3;
int resultOfAdding = x + y;
int resultOfMultiplying = x * y;
Understanding unary operators
Some operators are unary, meaning they work on a single operand and can be applied before or after the operand, as shown in the following pseudocode:
var resultOfOperationAfter = onlyOperand operator;
var resultOfOperationBefore = operator onlyOperand;
Examples of unary...