Do the following problems. The vast majority of these are taken directly from the textbook, because a lot of students are comforted by the idea of textbook problems. Turn in a hardcopy pdf, on the day of the Final Exam.
Readings: [Scott], Chapters 7 and 8, and skim 9 and 10. Consider the "Check Your Understanding" questions as part of your reading assignment (that is, solve as many as you can but do not turn in any solutions).
struct {
int n;
char c;
} A[10][10];
If the address of A[0][0] is 1000 (decimal), what is the address of A[3][7]?
double *a[n];
double (*b)[n];
double (*c[n])();
double (*d())[n];
void foo() {
int i;
printf("%d ", i++);
}
int main() {
int j;
for (j = 1; j <= 10; j++) foo();
}
Local variable i in subroutine foo is never initialized. On many systems, however,
the program will display repeatable behavior, printing 0 1 2 3 4 5 6 7 8
9. Suggest an explanation. Also explain why the behavior on other systems might
be different, or nondeterministic.
call foo(2)
print* 2
stop
end
subroutine foo(x)
x = x + 1
return
end
double (*foo(double (*)(double, double[]), double)) (double, ...);
Describe in English the type of foo.
class Foo {
public int a;
public String b;
}
...
class Bar extends Foo {
public float c;
public int b;
}
Does the representation of a Bar object contain one b field or two?
If two, are both accessible, or only one? Under what circumstances?
Answer for C++, Java, and Ruby. In the case of Ruby, show your
translation of the above Java code into the closest possible
Ruby code that maintains the spirit of the problem.
fun same_fringe t1 t2 = flatten t1 = flatten t2
Write a straightforward version of flatten in ML. How efficient
is same_fringe when the trees differ in their first few leaves?
How could you improve this, since, after all, ML is an eager,
not a lazy, functional language.