EECS 280 Final Exam Fall '18 - Term
Definitions Questions and Graded
Answers.
The "Rule of (the Big) Three" - If you need to declare EITHER a copy constructor, assignment
operator, or destructor, then you probably need to explicitly declare ALL three.
//
Alternately: if your program has dynamically-allocated memory, you probably need to declare
all three of these.
"friend" classes - If B is a class declared inside A, declaring A as a friend class of B means A can
see B's private variables.
//Note: Friendship DOESN'T go both ways! A can't say "B is my friend" if B is inside A.
Deep copy - Copies the actual object a pointer points to, not just the pointer itself, for a new
instance of a class.
Shallow copy - A copy that replicates only a pointer-to-object, and not the object itself, for a new
instance of a class.
Destructor - A member function that deletes the dynamically-allocated memory associated with
an object instance at the end of that object's lifetime (called automatically).
Virtual destructor - A destructor that ensures the proper corresponding destruction takes place in
derived classes that may contain member variables that are different from those of the base class.
, Copy constructor - A member function of an object that takes in a current object instance,
allocates memory for a new object instance, and gives that new instance the exact same member
variables as the old instance by initializing them.
Overloaded assignment operator - Combines the functionality of destructors and copy
constructors.
*this - A "hidden" member variable of every class that points to the current/working instance of
the class in your program.
3 types of recursion - Linear recursion, tail recursion, and tree recursion
Tail recursion/tail-recursive function - A recursive function in which the recursive statement is
the last statement that occurs in the entire recursive function. Differs from linear recursion
because the recursive call MUST be last.
Linear recursion/linear-recursive function - A recursive function that only makes one recursive
call in its entire implementation. Differs from tail recursion because this call doesn't need to be
the last statement.
Tree recursion/tree-recursive function - A recursive function that makes multiple recursive calls
throughout its body.
Dangling pointer - A pointer that points to a memory location which no longer contains the
object it originally pointed to; a pointer that points to unallocated memory.
Memory leak - When a piece of dynamically-allocated memory is not properly de-allocated by
the programmer.
Consequences of memory leaks - May slow down the program, crash the program, or (at worst)
cause undefined behavior.
Definitions Questions and Graded
Answers.
The "Rule of (the Big) Three" - If you need to declare EITHER a copy constructor, assignment
operator, or destructor, then you probably need to explicitly declare ALL three.
//
Alternately: if your program has dynamically-allocated memory, you probably need to declare
all three of these.
"friend" classes - If B is a class declared inside A, declaring A as a friend class of B means A can
see B's private variables.
//Note: Friendship DOESN'T go both ways! A can't say "B is my friend" if B is inside A.
Deep copy - Copies the actual object a pointer points to, not just the pointer itself, for a new
instance of a class.
Shallow copy - A copy that replicates only a pointer-to-object, and not the object itself, for a new
instance of a class.
Destructor - A member function that deletes the dynamically-allocated memory associated with
an object instance at the end of that object's lifetime (called automatically).
Virtual destructor - A destructor that ensures the proper corresponding destruction takes place in
derived classes that may contain member variables that are different from those of the base class.
, Copy constructor - A member function of an object that takes in a current object instance,
allocates memory for a new object instance, and gives that new instance the exact same member
variables as the old instance by initializing them.
Overloaded assignment operator - Combines the functionality of destructors and copy
constructors.
*this - A "hidden" member variable of every class that points to the current/working instance of
the class in your program.
3 types of recursion - Linear recursion, tail recursion, and tree recursion
Tail recursion/tail-recursive function - A recursive function in which the recursive statement is
the last statement that occurs in the entire recursive function. Differs from linear recursion
because the recursive call MUST be last.
Linear recursion/linear-recursive function - A recursive function that only makes one recursive
call in its entire implementation. Differs from tail recursion because this call doesn't need to be
the last statement.
Tree recursion/tree-recursive function - A recursive function that makes multiple recursive calls
throughout its body.
Dangling pointer - A pointer that points to a memory location which no longer contains the
object it originally pointed to; a pointer that points to unallocated memory.
Memory leak - When a piece of dynamically-allocated memory is not properly de-allocated by
the programmer.
Consequences of memory leaks - May slow down the program, crash the program, or (at worst)
cause undefined behavior.