In this post, we will see Arithmetic Expressions | PPL | Sebesta | Expressions and Assignment Statements | arithmetic expressions, ppl, sebesta, expressions and assignment statements
1. Arithmetic expression
In programming languages, arithmetic expressions
consist of operators, operands, parentheses, and function calls.
An operator can be unary, meaning it has a single operand, binary, meaning it has two operands, or ternary, meaning it has three operands.
In most programming languages, binary operators are infix, which means they appear between their operands, while in Lisp, it it prefix.
Following are the primary design issues for arithmetic expressions:
What are the operator precedence rules?
The precedences of the arithmetic operators of Ruby and the C-based languages are as follows:
** stands for exponentiation operator.
What are the operator associativity rules?
When an expression contains two adjacent 2 occurrences of operators with the same level of precedence, the question of which operator is evaluated first is answered by the associativity rules of the language.
Associativity in common languages is left to right, except that the exponentiation operator (when provided) sometimes associates right to left.
The associativity rules for a few common languages are given here:
Watch following video:
Watch on YouTube: https://www.youtube.com/watch?v=ZM_jGRm9i48