Module 3: Basic Semantics and Pointer Semantics Flashcards

1
Q

What is semantics concerned with?

A

Semantics is concerned with what the parse tree means.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the properties that we want from language semantics definitions? (Select all that apply)

a. Preciseness
b. Acceptability
c. Predictability
d. Complete

A

a. Preciseness
c. Predictability
d. Complete

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the ways that language semantics can be specified?

a. English specification
b. Reference implementation
c. Formal Language
d. All of the above

A

d. All of the above

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Given the line of code below, is this an explicit or implicit declaration?

int i;

A

This is an explicit declaration. We are saying that i is that name of the variable explicitly

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does the following represent?

target = test_value + 10

a. explicit declaration
b. implicit declaration

A

b. implicit declaration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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

a. How long is it valid
b. How to resolve the name
d. What declaration is the name mapped to

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What kind of scoping does the C programming language use?

a. Block-level
b. Function-level
c. None

A

a. Block-level

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is used to map the name to the declaration in scoping?

a. Variable table
b. Nothing
c. Declaration table
d. Symbol table

A

d. Symbol table

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the two types of scoping?

A

a. Static Scoping

b. Dynamic Scoping

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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

A

e. All of the above

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Using a box and circle diagram what does the x represent?

a. Name
b. Binding
c. Location
d. Value

A

a. Name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Using a box and circle diagram what does the box represent?

a. Name
b. Binding
c. Location
d. Value

A

c. Location

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Using a box and circle diagram what does the circle represent?

a. Name
b. Binding
c. Location
d. Value

A

d. Value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Using a box and circle diagram what does the line represent?

a. Name
b. Binding
c. Location
d. Value

A

b. Binding

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the two operations with pointers?

A

The address operator (&) and the deference operator (*)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

True or False: The & operator is a unary operator and can only be applied on an L value.

A

True.

This means that it can only be applied once and can not be applied on something like
&b
but not
&(b+c)

17
Q

What is the return value of &?

a. l-value
b. r-value

A

b. r-value of type T*

For example:
&x -> int*
this would take the address of x and turn it into an int

18
Q

True or False:

The difference operator can only be applied to l-values

A

False.

The difference operator can be applied to both l-value and r-value operators.

19
Q

If x is of type T* what does the box and circle diagram look like?

A

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.

20
Q

What type of return value does *X return?

a. l-value
b. r-value

A

a. l-value

21
Q

What memory does the malloc operation send values to?

a. global
b. heap
c. stack

A

b. heap

22
Q

True or False:

Every malloc results in a new location in the heap.

A

True

Every malloc does result in a new location in the heap

23
Q

What does malloc return?

A

Malloc will return the address of the value.

24
Q

What does *x mean?

A

Take the value of inside X, go to that address and return the value of that address. This is type of link.

25
Q

What is an alias?

A

Alias is when variables are associated with the same locations.

26
Q

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

A

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

27
Q

What is memory deallocation?

A

Memory deallocation is the process of how to release locations and associated addresses so that they may be reused later in program execution.

28
Q

What are the types of memory allocation?

a. Global allocation
b. Stack allocation
c. Variable allocation
d. Heap allocation

A

a. Global allocation
b. Stack allocation
d. Heap allocation

29
Q

True or False:

Global memory is never deallocated.

A

True, global memory is allocated once and the allocated memory is not deallocated

30
Q

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

A

b. It is allocated with nested scopes and function calls, the memory reserved is automatically deallocated when out of scope

31
Q

Explain heap allocation

A

Allocation is explicitly requested by the program (malloc and new) and has to be deallocated by calling things like free.

32
Q

What are the two types of memory errors?

A

a. Dangling Reference

b. Garbage

33
Q

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

a. Reference to a memory address that was originally allocated but is now deallocated

34
Q

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.

A

c. Memory that has been allocated in the heap and has not been explicitly deallocated, yet is not accessible by the program

35
Q

What is a common outcome of having a memory error?

A

A segmentation fault