Monday, April 8, 2013

KBP Assignment

Concepts of Programming Language 10th edition
Chapter 7

For Mr. TriDjoko Wahjono

Review Question


1. Define operator precedence and operator associativity.

Operator precedence is the order of the operations.
Operator associativity: if there are more than one operator, no matter evaluate the left operator first or evaluate the right operator first, the result will be the same.


2. What is a ternary operator?

An operator that has three operands.

3. What is a prefix operator?
An operator which precede their operands.

5. What is a nonassociative operator?
Non-associative operators are operators that have no defined behavior when used in sequence in an expression.

11. What is an overloaded operator?
The multiple use of an operator is called operator overloading.

14. What is a mixed-mode expression?
There are more than one type of operand in the expression.

18. What is short-circuit evaluation?
The result of expression is determined without all of the operands and/or operators.

Problem Set


1. When might you want the compiler to ignore type differences in an expression?

When you want to evaluate a string as a number and vice-versa

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's simpler than the normal <operand> = <operand> + <some values> form, and it can save much time.

6. Should C's single-operand assignment forms (for example, ++count) be included in other languages (that do not already have them)? Why or why not?
Yes, because it's simpler than the normal addition <operand> = <operand> + 1; and it can save much time.

7. Describe a situation in which the add operator in a programming language would not be commutative.
An expression such as : x + fun(y), and fun(y) changes x.

20. Consider the following C program:
int fun(int *i) {
*i +=5;
return 4;
}
void main() {
int x = 3;
x = x+fun(&x);
}
What is the value of x after the assignment statement in main, assuming :
a. operands are evaluated left to right.
b. operands are evaluated right to left.
a.) 7
b.) 12

No comments:

Post a Comment