Arizona State University
Computer Science and Engineering
CSE 340 - Spring 2014
Final Exam. Solution
NAME:
The following should be signed when you hand in your paper.
I give my word of honor and solemnly swear that
...
Arizona State University
Computer Science and Engineering
CSE 340 - Spring 2014
Final Exam. Solution
NAME:
The following should be signed when you hand in your paper.
I give my word of honor and solemnly swear that I did not violate
the academic integrity policy in answering the questions of the exam
Read everything carefully. Some statements can be tricky. Not all questions
have equal weight.
1[ 5 points ] Consider the following C declarations:
struct G; // declaration
struct F {
int y;
struct D* next;
};
struct E {
int x;
struct F next;
};
struct D {
int x;
struct E next;
};
struct H {
int x;
int (*next)(struct G); // pointer to a function that takes
// struct G as parameter and returns int
};
struct G { // definition
float x;
struct H next[10];
};
Assume that the size of a structure is the sum of the sizes of its fields and
an int fields requires 6 bytes of space, a pointer field requires 4 bytes of space
and a float field requires 8 bytes of space. Write your answer in the box:
1. sizeof(D) = 22 (int + struct E)
2. sizeof(E) = 16 (int + struct F)
3. sizeof(F) = 10 (int + pointer)
4. sizeof(G) = 8 (float) + 10*10 (array of struct H) = 108
5. sizeof(H) = 10 (int + pointer)
2[15 points ] Consider the following function definition
func f(a,b,c,d) = if c(c(a,b),b) then
d[b]
else
c
Assuming Hindley-Milner type inference is done, fill in the blank for each of the
following (assume arithmetic can only be done on numeric types int or real).
You can parametrize you answer with polymorphic types, but you should use
the names of the types consistently for the various answers.
Answer:
1. Ta = bool
2. Tb = int
3. Tc = bool (*) (bool, int)
4. Td = array of bool(*)(bool, int)
5. Tf = bool (*)(bool,int) (*) (Ta, Tb,Tc,Td)
3[15 points] Consider the following C code
struct T {
[Show More]