1) We should all be accustomed to the PEMDAS operator precedence rules (Parenthesis, exponentials, multiply, modulus, divide, addition, and subtraction) for constant integer expressions. For example, (3 + 4) X (6 -1) = 35 Please describe in your own words how the + and - symbols are used in ways other than for addition and subtraction. Describe what happens to the operator precedence rules when you use the + and - symbols in that manner.
Solution:
As PEDMAS i.e. (Parenthesis, exponentials, multiply, modulus, divide, addition, and subtraction) defines the order of operation in an expression but conflict occurs when two operator of same precedence are used in the expression. For example "*" and "/" have same precedence and then comes the associativity rule, which can be either from left to right or right to left.
In case of "+" and "-", which are of same precedence and here, associativity rule is from left to right. For example:
1:
200 + 20 / 2 - 3 * 20
=> 200 + 10 - 60
=> 210 - 60
=> 150
2:
500 - 20 * 3 + 100 / 5
=> 500 - 60 + 20
=> 440 + 20
=> 460
There are very specific uses of "+" and "-" operators in programming languages. "+" is used as concatenation operator and "-" operator is used as negation operator.
For example:
"Sam "+"karn" results in Sam karn and - (- 12) results in +12.
Get Answers For Free
Most questions answered within 1 hours.