Module 3: Basic Semantics and Pointer Semantics Flashcards
What is semantics concerned with?
Semantics is concerned with what the parse tree means.
What are the properties that we want from language semantics definitions? (Select all that apply)
a. Preciseness
b. Acceptability
c. Predictability
d. Complete
a. Preciseness
c. Predictability
d. Complete
What are the ways that language semantics can be specified?
a. English specification
b. Reference implementation
c. Formal Language
d. All of the above
d. All of the above
Given the line of code below, is this an explicit or implicit declaration?
int i;
This is an explicit declaration. We are saying that i is that name of the variable explicitly
What does the following represent?
target = test_value + 10
a. explicit declaration
b. implicit declaration
b. implicit declaration
What does scope cover in semantics?
a. How long is the name valid?
b. How to resolve the name?
c. What is the name?
d. What declaration is the name mapped to
a. How long is it valid
b. How to resolve the name
d. What declaration is the name mapped to
What kind of scoping does the C programming language use?
a. Block-level
b. Function-level
c. None
a. Block-level
What is used to map the name to the declaration in scoping?
a. Variable table
b. Nothing
c. Declaration table
d. Symbol table
d. Symbol table
What are the two types of scoping?
a. Static Scoping
b. Dynamic Scoping
How can function calls be resolved to appropriate functions?
a. Names
b. Names + return type?
c. Names + parameter number?
d. Names + parameter number + parameter types
e. All of the above
e. All of the above
Using a box and circle diagram what does the x represent?
a. Name
b. Binding
c. Location
d. Value
a. Name
Using a box and circle diagram what does the box represent?
a. Name
b. Binding
c. Location
d. Value
c. Location
Using a box and circle diagram what does the circle represent?
a. Name
b. Binding
c. Location
d. Value
d. Value
Using a box and circle diagram what does the line represent?
a. Name
b. Binding
c. Location
d. Value
b. Binding
What are the two operations with pointers?
The address operator (&) and the deference operator (*)
True or False: The & operator is a unary operator and can only be applied on an L value.
True.
This means that it can only be applied once and can not be applied on something like
&b
but not
&(b+c)
What is the return value of &?
a. l-value
b. r-value
b. r-value of type T*
For example:
&x -> int*
this would take the address of x and turn it into an int
True or False:
The difference operator can only be applied to l-values
False.
The difference operator can be applied to both l-value and r-value operators.
If x is of type T* what does the box and circle diagram look like?
It gives the typical box diagram of X with Xv inside of the circle. If we call *X we take the address of Xv and find the location that has that address Xv. *X will get the value V from the address and return it. V has to be of type T for it to work.
What type of return value does *X return?
a. l-value
b. r-value
a. l-value
What memory does the malloc operation send values to?
a. global
b. heap
c. stack
b. heap
True or False:
Every malloc results in a new location in the heap.
True
Every malloc does result in a new location in the heap
What does malloc return?
Malloc will return the address of the value.
What does *x mean?
Take the value of inside X, go to that address and return the value of that address. This is type of link.
What is an alias?
Alias is when variables are associated with the same locations.
How can you create new locations and reserve the associated address?
a. Find the address and make it the address
b. Finding memory that is not currently reserved
c. Associate that memory with a variable name or reserving the memory and returning the address of the memory
d. All of the above
b. Finding memory that is not currently reserved
c. Associate that memory with a variable name or reserving the memory and returning the address of the memory
What is memory deallocation?
Memory deallocation is the process of how to release locations and associated addresses so that they may be reused later in program execution.
What are the types of memory allocation?
a. Global allocation
b. Stack allocation
c. Variable allocation
d. Heap allocation
a. Global allocation
b. Stack allocation
d. Heap allocation
True or False:
Global memory is never deallocated.
True, global memory is allocated once and the allocated memory is not deallocated
Which of the following best explains stack allocation?
a. It is allocated once and is not deallocated after
b. It is allocated with nested scopes and function calls, the memory reserved is automatically deallocated when out of scope
c. Allocation is explicitly requested by the program
d. It
b. It is allocated with nested scopes and function calls, the memory reserved is automatically deallocated when out of scope
Explain heap allocation
Allocation is explicitly requested by the program (malloc and new) and has to be deallocated by calling things like free.
What are the two types of memory errors?
a. Dangling Reference
b. Garbage
What is a dangling reference error?
a. Reference to a memory address that was originally allocated but is now deallocated.
b. Reference to a memory address that has been deallocated but is now allocated
c. Memory that has been allocated in the heap and has not been explicitly deallocated, yet is not accessible by the program
a. Reference to a memory address that was originally allocated but is now deallocated
What is a garbage memory error?
a. Reference to a memory address that was originally allocated but is now deallocated.
b. Reference to a memory address that has been deallocated but is now allocated
c. Memory that has been allocated in the heap and has not been explicitly deallocated, yet is not accessible by the program
d. Memory that has been allocated in the stack and has not been explicitly deallocated, yet is not accessible by the program.
c. Memory that has been allocated in the heap and has not been explicitly deallocated, yet is not accessible by the program
What is a common outcome of having a memory error?
A segmentation fault