chapter 7.

3 Apr


1.define operator precedence and oerator associativity.

Operator precedence is a level of priority of each operator decide which operator is applied first when evaluating the statement.

Operator associativity is applied when operators have the same level of operator precedence,
to decide which operator is applied first when evaluating the statement.

2.what is ternary operator?

ternary operator is an operator which need three operand.

3.what is a prefix operator?

prefix operator is operator which appear before operand.

4.what operator usually has right associativity?

exponential operator is.

5.what is non-associative operator?

Non-associative operators are operators that have no defined behavior when used in sequence in an expression.

6.what associativity rule used by APL?

APL use right associativity rule.

7. What is the difference between the way operators are implemented in C++ and Ruby?

all of the arithmetic, relational, and assignment operators, as well as array indexing, shifts, and bitwise logic operators, are
implemented as methods in Ruby.

8. Define functional side effect.

functional side effect, occurs when the function changes either one of its parameters or a global variable.

9. What is a coercion?

coercion was defined as implicit type of conversion that is initiated by the compiler.


20. int fun(int *i) {
*i += 5;
return 4;
void main() {
int x = 3;
x = x + fun(&x);

a. operands are evaluated left to right.
x = 7.
b. operands are evaluated right to left.
x = 12.

13. int fun(int *k) { 10
*k += 4; 14
return 3 * (*k) – 1; 41

void main() {
int i = 10, j = 10, sum1, sum2;
sum1 = (i / 2) + fun(&i); 5+41
sum2 = fun(&j) + (j / 2); 41+7

a. if the operands in the expressions are evaluated left to right?
sum1 = 46
sum2 = 48

b. if the operands in the expressions are evaluated right to left?
sum1 = 48
sum2 = 46

9. Precedence
Highest *, /, not
^ +, –, &, mod
| – (unary)
| =, /=, < , =, >
v and
Lowest or, xor

Associativity Left to right

a. a * b – 1 + c
(((a * b) – 1) + c)

b. a * (b – 1) / c mod d
(((a * (b – 1)) / c) mod d)

c. (a – b) / c & (d * e / a – 3)
(((a – b) / c) & (((d * e) / a) – 3))

d. -a or c = d and e
((((-a) or c) = d) and e)

e. a > b xor c or d b) xor c) or (d <= 17))

f. -a + b
-(a + b)

1. when you want to add int to float.

5. Should C’s assigning operations (for example, +=) be included in other
languages (that do not already have them)? Why or why not?

yes. because it would result a same value wheter it left precedence or right precedence.

4. Would it be a good idea to eliminate all operator precedence rules and
require parentheses to show the desired precedence in expressions? Why or why not?

yes. because it more safe that way.

8. Describe a situation in which the add operator in a programming language
would not be associative.

A = A + A++;


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: