2. How does a decimal value waste memory space?
14. Write a short discussion of what was lost and what was gained in Javas designers decision to not include the pointers of C++.
9. Assume the following rules of associativity and precedence for expressions: see image.
Show the order of evaluation of the following expressions by parenthesizing all subexpressions and placing a superscript on the right parenthesis to indicate order. For example, for the expression
a + b * c + d
13. Let the function fun be defined as
int fun(int *k) {
*k += 4;
return 3 * (*k) - 1;
}
Suppose fun is used in a program as follows:
void main() {
int i = 10, j = 10, sum1, sum2;
sum1 = (i / 2) + fun(&i);
sum2 = fun(&j) + (j / 2);
}
What are the values of sum1 and sum2
9. What are the arguments both for and against the exclusive use of Boolean expressions in the control statements in Java (as opposed to also allowing arithmetic expressions, as in C++)?
4. Consider the following C program segment. Rewrite it using no gotos or breaks .
j = -3;
for (i = 0; i < 3; i++) {
switch (j + 2) {
case 3:
case 2: j--; break;
case 0: j += 2; break;
default: j = 0;
}
if (j > 0) break;
j = 3 - i
}
7. What is the difference between functional programming languages and imperative languages?
8. What is the scope of a "typical" Scheme variable?
9. Is operator associativity or precedence a factor in Scheme? Why or why not?
10. What does the following Scheme function do? Write comments for each line.
1. Write a Scheme function that sums the numbers in a list. For example, your function is called listsum, then (listsum '(1 2 3 4 5 4 3 2 1)) should return 25
2. Write a Scheme function that takes a list and a number, n, and returns the nth element of the list. For example, your function is called getelement, then (getelement '(1 2 3 4 5) 3) will return 3.