Академический Документы
Профессиональный Документы
Культура Документы
CSCI 524.1240
Final Exam
FA 2009
Professor E. Chen
2. There are two possible pointer problems, dangling pointers and lost heapdynamic variable (also called garbage). Please describe both in detail.
3. The following function is defined in C++ with four formal parameters. Please
explain each parameter according to the mode and how it could be used in the
function?
void function1 ( const int &p1, int p2, int &p3, int *p4)
4. Please specify how the Boolean data type is represented in both VB and C++.
5. What is a short-circuit evaluation? Why it is useful? What kind of side effect it
might generate?
6. Please explain the following Implementation Models of Parameter Passing.
Pass-By-Value
Pass-By-Result
Pass-By-Value-Result
Pass-By-Reference
7. There are at least two distinct ways in which non-local references in a dynamicscoped language can be implemented: Deep access and Shallow access. Please
use the following procedure definition and sequence of procedure calls to draw
the Deep access diagram and explain them.
procedure C;
integer x, y, z ;
begin
x := u + v ;
end;
procedure B;
integer w, x, a, b, c ;
begin
end ;
procedure A;
integer v, w , b, c ;
begin
end ;
program MAIN_6;
integer v, u, a ;
begin
end .
Suppose the following sequence of procedure calls occurs:
MAIN_6 calls A
A calls A
A calls B
B calls C
8. Please draw an activation record instance and shows the static chains and the
actual reference pairs (chain_offset, local_offset) for variable A at point 1, 2, &
3 based on the program provided below, and the sequence of procedure calls.
(This is an ALGOL-like programming language)
program MAIN_2;
(depth : 0)
var X, Y, Z : integer ;
------------------------------------------------------------procedure BIGSUB ;
(depth : 1)
var A, B, C, D, X, Z : integer ;
-------------------------------------------------procedure SUB1 ;
(depth : 2)
var A, D, Y : integer ;
begin { SUB1 }
A := B + C ;
1
.
end ; { SUB1 }
---------------------------------------------------------------------------------------------------procedure SUB2 ( X : integer ) ;
(depth : 2)
var B, E, Y : integer ;
------------------------------------procedure SUB3 ;
(depth : 3)
var C, E : integer ;
begin { SUB3 }
SUB1;
E := B + A ;
2
end ; { SUB3 }
-----------------------------------begin { SUB2}
SUB3 ;
A := D + E ;
3
end ; { SUB2 }
-------------------------------------------------begin { BIGSUB }
SUB2(7) ;
end ; { BIGSUB }
------------------------------------------------------------begin { MAIN_2 }
BIGSUB ;
end. { MAIN_2 }