Operators are the constructs, which can manipulate the value of operands. Consider the expression 31 + 7 = 38. Here, 31 and 7 are called the operands and + is called the operator.
Spla language supports the following types of operators −
Let us have a look at all the operators one by one.
Assume variable a holds the value 7 and variable b holds the value 31, then −
| Operator | Description | Example |
|---|---|---|
| + Addition | Adds values on either side of the operator. | a + b = 38 |
| - Subtraction | Subtracts right hand operand from left hand operand. | a – b = -24 |
| * Multiplication | Multiplies values on either side of the operator | a * b = 217 |
| / Division | Divides left hand operand by right hand operand | b / a = 4.42 |
| % Modulus | Divides left hand operand by right hand operand and returns remainder | b % a = 3 |
| ^ Exponent | Performs exponential (power) calculation on operators | a^b =7 to the power 31 |
These operators compare the values on either side of them and decide the relation among them. They are also called Relational operators.
Assume variable a holds the value 7 and variable b holds the value 31, then −
| Operator | Description | Example |
|---|---|---|
| == | If the values of two operands are equal, then the condition becomes true. | (a == b) is not true. |
| != | If values of two operands are not equal, then condition becomes true. | (a!= b) is true. |
| > | If the value of left operand is greater than the value of right operand, then condition becomes true. | (a > b) is not true. |
| < | If the value of left operand is less than the value of right operand, then condition becomes true. | (a < b) is true. |
| >= | If the value of left operand is greater than or equal to the value of right operand, then condition becomes true. | (a >= b) is not true. |
| <= | If the value of left operand is less than or equal to the value of right operand, then condition becomes true. | (a <= b) is true. |
Assume variable a holds the value 7 and variable b holds the value 31, then −
| Operator | Description | Example |
|---|---|---|
| = | Assigns values from right side operands to left side operand | c = a + b assigns value of a + b into c |
| += Add AND | It adds right operand to the left operand and assign the result to left operand | c += a is equivalent to c = c + a |
| -= Subtract AND | It subtracts right operand from the left operand and assign the result to left operand | c -= a is equivalent to c = c - a |
| *= Multiply AND | It multiplies right operand with the left operand and assign the result to left operand | c *= a is equivalent to c = c * a |
| /= Divide AND | It divides left operand with the right operand and assign the result to left operand | c /= a is equivalent to c = c / a, c /= a is equivalent to c = c / a |
| %= Modulus AND | It takes modulus using two operands and assign the result to left operand | c %= a is equivalent to c = c % a |
| ^= Exponent AND | Performs exponential (power) calculation on operators and assign value to the left operand | c ^= a is equivalent to c = c ^ a |