Selasa, 09 April 2013

Chapter 7

Review Questions

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

4. What operator usually has right associativity?
Exponentiation operator.

8. Define functional side effect.
Functional side effect is a side effect that occurs when the function changes either one of its parameters or a global variable.

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

11. What is an overloaded operator?
Operator Overloading is a specific case of polymorphism, where different operators have different implementations depending on their arguments.

24. What two languages include multiple assignments?
Ruby and Perl.

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?
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.


15. Explain why it is difficult to eliminate functional side effects in C.
All functions in C are subprograms and each of them return only one value.To return more that one value, we have to use parameters and if the parameters are pointers it may change the value of variables. Another problem is if the function changes the value of a global variable, it may affect the whole program.


21. Why does Java specify that operands in expressions are all evaluated in left-to-right order?
Java has well defined rules for specifying order in which in expression are all evaluated in left-to-right order, this is done to make Java easier to code, as left-to-right order is how most of us learned it in our early school on the mathematics subject. left-to-right order is also one of the most used guidelines in order to evaluate operands in an expression. This is also done to prevent functional side effect from happening.







Tidak ada komentar:

Posting Komentar