Programming Exercises 345
- What is your primary argument against (or for) the operator precedence
rules of APL? - Explain why it is difficult to eliminate functional side effects in C.
- For some language of your choice, make up a list of operator symbols
that could be used to eliminate all operator overloading. - Determine whether the narrowing explicit type conversions in two lan-
guages you know provide error messages when a converted value loses its
usefulness. - Should an optimizing compiler for C or C++ be allowed to change the
order of subexpressions in a Boolean expression? Why or why not? - Answer the question in Problem 17 for Ada.
- 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.
- Why does Java specify that operands in expressions are all evaluated in
left-to-right order? - Explain how the coercion rules of a language affect its error detection.
PROGRAMMING EXERCISES
- Run the code given in Problem 13 (in the Problem Set) on some system
that supports C to determine the values of sum1 and sum2. Explain the
results. - Rewrite the program of Programming Exercise 1 in C++, Java, and C#,
run them, and compare the results. - Write a test program in your favorite language that determines and
outputs the precedence and associativity of its arithmetic and Boolean
operators.