Title: Review 2
1Review 2
2Binding
- What is binding?
- When does binding of names occur?
- What is a variable?
3Binding and Attributes
- Name and describe 6 attributes that can be bound
to a variable name? - When does binding of names occur?
-
- What is an alias?
-
4Three Memory areas
- The memory area allocated for a program's data is
divided into 3 areas. What are their names? -
-
-
- What kind of values are placed in each area?
-
-
-
- Name a language that allocates all storage in
only one of these area? -
5Scope
- There are 2 types of scope rules. What are they
called? -
-
- Most languages use which type of scope?
- C
int x 10 int fun(int x) x x x return
x int main( ) int y x int x
fun(y) // what is x ? // what is y ?
6Linking of names
- What is the name of the software that joins
object files and resolves external references in
object files? -
- Does this program verify data types?
-
/ File 1 / char foo extern double
bar ... printf("s", foo) printf("f", bar)
/ File 2 / extern double foo char bar
"foo!" ... printf("d", foo) printf("s", bar)
7Referencing environment
- What is a referencing environment?
-
- In the calculator, how do we store the
referencing environment? -
- Is the Symbol Table needed by the binary
(executable) program? - Is the symbol table included in the output of the
linker (compiled program)? - On Linux, how can you get rid of the symbol
table?
8Symbol Table
- What information is in the symbol table?
-
-
- Is the Symbol Table needed by the binary
(executable) program? - Is the symbol table included in the output of the
linker (compiled program)? - On Linux, how can you get rid of the symbol table
in a binary (compiled) program file?
9Remembering values
- I want to write a C function that tells me how
many times the function has been called.
counter( ) // returns 1 counter( ) //
returns 2 counter( ) // returns 3 ...
- how can I write a counter() function that
remembers how many times it has been called?
(without using global variables) -
int counter( ) static int count 0 return
count
10Call By...
- What are the names of the 3 methods of passing
parameters to subroutines? - Describe each one.
- What language useswhich param passing
method?Java, C, C, Fortran-77
int fun(int x) x x x return x int
main( ) int y 20 printf( fun(y)
) printf( y ) // what is printed?
11Test the param passing method?
- Design a simple program to determine which
parameter passing method is being used.
void fun( ) int main( )
12Values versus References
- What is a value data type?
- What is a reference data type?
-
-
Integer fun(Integer x) x x x return
x int main( ) Integer x 10 Integer y
fun(x) // what is x ? // is (y x) ?
int fun(int x) x x x return x int
main( ) int x 10 int y fun(x) // what
is x ? // is (y x) ?
13What does this do?
what does this do? sub(, List). sub(HT,
List) - member(H, List), sub(T, List).
14What does this do?
Underscore (_) means "don't care". It accepts any
value.
what does this do? foo(, _, ). foo(HT,
List, HP) - member(H, List), foo(T, List,
P). foo(HT, List, P) - not( member(H, List)
), foo(T, List, P).
15Memory and VMT
Person - name Person(name String) getName()
String
- Person kung new Foo("Kung",20)
- Draw a picture of the contents and layout of
memory used by kung. - Draw the VMT for Foo, showing methods in the
correct order. - Refactor
- how does the picture change if nextID is moved to
the Person class?
Foo - nextID int - age int Foo( String,
int) getAge() inttoString() String