Review 2 - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Review 2

Description:

Name and describe 6 attributes that can be bound to a variable name? ... Person kung = new Foo('Kung',20); Draw a picture of the contents and layout of memory ... – PowerPoint PPT presentation

Number of Views:30
Avg rating:3.0/5.0
Slides: 16
Provided by: kenneth67
Category:
Tags: kung | review

less

Transcript and Presenter's Notes

Title: Review 2


1
Review 2
2
Binding
  • What is binding?
  • When does binding of names occur?
  • What is a variable?

3
Binding 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?

4
Three 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?

5
Scope
  • 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 ?
6
Linking 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)
7
Referencing 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?

8
Symbol 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?

9
Remembering 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
10
Call 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?
11
Test the param passing method?
  • Design a simple program to determine which
    parameter passing method is being used.

void fun( ) int main( )
12
Values 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) ?
13
What does this do?
what does this do? sub(, List). sub(HT,
List) - member(H, List), sub(T, List).
14
What 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).
15
Memory 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
Write a Comment
User Comments (0)
About PowerShow.com