Saturday, April 6, 2013

Concepts of Programming Languages 10th Edition : Chapter 7


Created By : Robert W. Sebesta
Lecturer : Mr. Tri Djoko Wahjono, Ir. M.Sc
Answered by : Shirley Halim Ng
NIM : 1601233805
Class : 02PCT

 Review questions

 2.    What is a ternary operator?
        => A ternary operator is an operator with three operands.

 3.    What is a prefix operator?
          => A prefix operator is an operator that precede their operands

 9.    What is a coercion?
        => A coercion is the implicit type convertion.

10. What is a conditional expression?
        => Conditional expression is a statement that uses if-then-else statements.

11. What is an overloaded operator?
        => An overloaded operator is the multiple uses of an operator.

15. What is referential transparency?
        => Referential transparency is two expressions in the program that have the same value can be substituted for one another anywhere in the program without affecting the action of the program.

28. What is a cast?
        => A cast is an operator to convert a data type into another data types.


Problem Set

 3.    Do you think the elimination of overloaded operators in your favorite language would be beneficial? Why or why not?
=> I think it is not beneficial because it can be ambigious if we want to use that operator with the same type.


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 we can make the operator simpler than before. We can just write a+=b instead a=a+b.

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. 12
     b. 7

21. Why does Java specify that operands in expressions are all evaluated in left-to-right order?
=> Java specify that operands in expressions are all evaluated in left-to-right order because Java is an associative language because associative in common language is evaluated from left to right.


No comments:

Post a Comment