Professional Documents
Culture Documents
: 1122700625
1+(2*3)=7
evaluated first
(2^2)+4=8
**
Unary+,*,/,%
Binary +,-
Lowest
Operator Associativity is define the rule which the expression has evaluated first when
two operators has the same level of precedence. Associativity usually is left to right
except when the exponentiation operator is right to left.
3-2+1=2
2^(2^2)=16
Associativity Rule
*,/,+,-
Left
**
Right
Left
==, !=
Left
&&, ||
Left
For example:
(A-B) *C
where A=4, B=2 and C= 4
(4-2)*4=8
(2+2)+(3+3)
(4)+(6)=10
Explanation
Let a be 10 but the fun(a) there is an effect
and it will return 20
a=10;
b=a+fun(a);
Functional Side Effect is a special type of side effect, where the evaluation of a function
affects the value of others operand the same expression. There are two possible solutions
for solving Operand Evaluation Order by allowing a function change to global variable or
its parameter
Explanation
Assume the a is int type but it is the mixed-
float b,c,d;
d=a+b;
Most of the programming language can do explicit conversions for both widening and
narrowing. There are two types of type conversion which are Casts and Coercion. Casts is
refer as the explicit conversions whereas the coercions is the inexplicit conversions.
Example
Coercion
Explanation
K is float and y is int therefore y need to
k+y
Casts
type of k
A is the int and b is double data type
a=int(b)
Relational expressions has two operands and one relational operator. The value of a
relational expression is Boolean. The operation which to determine the truth or false of
the expression which depends on the operand types.
Lowest
||
Short circuit evalution is the expression to determine the result without evaluating all
operands or operators. For example as below:
Example
(5*7) * (13-1/a)
Explanation
If a is 0, because 12/a the result will be 0
and there is no need evaluate the 5*7
In Java,C and C++ programming language the && and || are short circuit but when & and
| are used they are no short circuit and they will use for the Boolean valued operands. But
for others programming language such as Ruby, Perl and Python they are short circuit.
Assignment statement is used the equal (=) sign for assign the operands in the expression.
The use of these operator must be different from the equal sign to avoid the confusion
with their assignment operator. Example as below:
Example
Char name = Ali;
Explanation
The variable of name is assign to character
of Ali
Explanation
During the beginning the value of a is 0
Int b=1;
a=a+b
Explanation
++a is a prefix add 1 to a and it will the
++a;
int a=0;
a++;
count ++;
Assignment as an Expression which produce the result, has the same value assigned to
the target. It can be used as an expression and operand in other expressions.
Example
If ((input=getchar()) !=EOF) {}
Explanation
The getchar() is assigned to the input get
string from keyboard input. Then the input
will compare with the EOF. If the input
does not match with the EOF therefore the
statement will not executed.
Explanation
In this example the a is assigned to 10, b is
assigned to 20 and c is assigned to 30 this
can be done using multiple assignment
Reference
1) ROBERT W.SEBESTA. (2012). Chapter 7 Expressions and Assignment
Statements (pp.317-345). CONCEPTS OF Programming Languages TENTH
EDITION.
2) What is the difference between ++i and i++(2008).Retrieved from
http://stackoverflow.com/questions/24853/what-is-the-difference-between-i-and-i
3) Difference between i++ and ++i in a loop? (2009). Retrieved from
http://stackoverflow.com/questions/484462/difference-between-i-and-i-in-a-loop
4) What is a side effect?(2011). Retrieved from
http://programmers.stackexchange.com/questions/40297/what-is-a-side-effect
Appendix