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.Organize your work in your CVS repository. The following is the suggested structure:
homework
cmsi386
src
main
docs
hw5.tex
<diagram source files>, if any
<images>, if any
ml
flatten.sml (Problem 11)
quicksort.sml (Problem 12)
test
ml
flattentest.sml (Problem 11)
quicksorttest.sml (Problem 11)
Your LaTeX file will contain solutions to each problem, numbered, and in order. You may embed source code in the document, or give the answer as "See <filename>" and submit the sources for these answers at the end of the document. Generate a pdf from the LaTeX file and hand in a printed copy.
Notes