Docsity

Midterm Exam Questions for CSE 131B, Spring 2007 - Prof. Richard Ord, Exams of Computer Science

Partial preview of the text

Download Midterm Exam Questions for CSE 131B, Spring 2007 - Prof. Richard Ord and more Exams Computer Science in PDF only on Docsity!

Signature ___________________ Name ______________________

Login Name _________________ Student ID __________________

Midterm

CSE 131B

Spring 2007

Page 1 ___________ (21 points)

Page 2 ___________ (18 points)

Page 3 ___________ (21 points)

Page 4 ___________ (18 points)

Page 5 ___________ (22 points)

Subtotal ___________(100 points)

Page 6 ___________ (5 points)

Extra Credit

Total ___________

1. Assume the following definitions are correct: (2 pts each)

ALIAS rec1 = RECORD ptr : POINTER TO FLOAT; END;

ALIAS rec2 = RECORD ptr : POINTER TO rec1; END;

VAR ptr : POINTER TO rec2; VAR a, b : FLOAT;

a) What type is ptr^.ptr^?

b) What type is ptr^.ptr^.ptr?

c) What type is ptr^.ptr?

d) What type is ptr^.ptr^.ptr^?

For the following, assume each statement is independent of each other. You cannot use the result of a previous

statement in the answer for a subsequent question. You can only use the above vars and types. You cannot use

NIL. You can assume loose name equivalence and RECORD assignment is valid throughout.

e) Write the Oberon statement to assign variable b the value of the float pointed to by ptr in rec1.

b :=

f) Write a valid statement with variable c (defined below) on the lhs (left hand side) of the assignment

statement. You cannot use c or NIL.

VAR c : rec2;

c :=

g) Using the Right-Left rule write the C definition of a variable named screwball that is an array of 9 elements

where each array element is of type pointer to a function which takes two arguments, a pointer to a pointer to a

char and a float, and returns a pointer to an array of 6 elements where each array element is of type pointer to

struct student. (9 pts)

3. Check #19a and #19b: How did your group implement the management of and semantic checks associated

with function overloading? Talk about (9 pts)

a) what you inserted into the symbol table

b) how you implemented the checking for illegal overloaded function definitions

c) how you implemented the checking for illegal overloaded function calls.

Given the following array definition

/* C */

float x[25][33];

write the assembly level address calculation expression taking into account scalar arithmetic to access

x[i][j]

(( x + _________________________________________ ) + _______________________________________ )

The result is the address of where we can find this array element. (8 pts)

Given the array declaration

C

short a[3][5];

Mark with an A the memory location(s) where we would find

a[1][1] a:

low memory high memory

Each box represents a byte in memory. (4 pts)

4. Briefly discuss 3 different ways/mechanisms discussed in class to subvert type checking in C. Multiple

examples of the same general mechanism just counts as 1 way. (2 pts each on this page)

What mechanisms/features of Java help to prevent the following which can/do regularly occur in C and are

difficult for the compiler to detect?

a) dangling pointers/references into the Heap

b) dangling pointers/references into the Stack

c) memory leaks

What part(s) of a compiler make up the front end?

What part(s) of a compiler make up the back end?

Which class from Project I should be the only class that contains a member "m_value" to hold an actual value?

Extra Credit (5 points)

What gets printed by the following C program?

#include <stdio.h>

int main() { char a[] = "Me? I want to go"; char b[] = "to Porter's Pub"; char c[] = "and don't you, too?"; char *ptr = b;

printf( "%c\n", *(ptr = ptr + 3) ); _______

printf( "%c\n", toupper( *c + 1 ) ); _______

printf( "%c\n", b[strlen(a) - 2] ); _______

printf( "%c\n", *(a + 7) ); _______

printf( "%c\n", ptr[5] ); _______

printf( "%c\n", ptr[5] + 1 ); _______ return 0; }

Scratch Paper