Programming (4th Edition) – Solutions
Manual by Dawson PDF
Using aggregation means. - answer-Combining classes so that one is a part of another
To allocate memory in the heap, use what keyword? - answer-new
To free memory on the heap that was previously allocated, use what keyword? - answer-delete
A friend function can access even private data members of a particular class, even though it
isn't a class-specific function - answer-True
How many times must you write the function prototype(name, return type, parameters) for a
friend function - answer-3
How do we declare a function as a friend function to a class? - answer-Write the function's
prototype in the class definition with keyword "friend"
Only global functions can be friend function - answer-True
Overloading an operator means: - answer-Giving special functionality to operators that are
passed new object types
1
,To overload the + operator, define a function with the name.. - answer-operator+
A benefit of using dynamic memory (the heap) is: - answer-Both A and B
Having more control of the efficient use of memory
Accessing objects created there in functions that have ended
When using the "new" keyword with an "int" variable, what is returned? - answer-A memory
address on the heap
Which of the following is the correct way to initialize a value on the heap? - answer-int* pHeap
= new int(10);
When a function that contains a variable stored in the heap ends, the memory used by that
variable is freed automatically. - answer-False
A good way to handle dangling pointers is to. - answer-Assign their value to "0" or "null"
A dangling pointer: - answer-Is a pointer pointing to an empty or invalid location
A memory leak is caused when: - answer-We lose access to allocated memory on the heap
When re-assigning a pointer to a new memory location that previously pointed to a value on
the heap, how can we get access to the original value? - answer-You can't, this causes a
memory leak and the value is lost?
2
, What should we need to do to avoid memory leaks when an object has a data member that is a
pointer to a heap? - answer-Overload the destructor function to delete the pointer
What name do we give the function that we want to use as our class destructor function -
answer-ClassName::~ClassName
If we define own constructor function, we must call it explicitly on all objects with the "delete"
keyword - answer-False
The custom destructor we define will be called automatically any time the object would
normally be cleared away, such as at the end of a function. - answer-True
Which of the following is a scenario where an object would be copied automatically in
memory? - answer-All of the above
When the object is passed by value to a function(not referenced)
When the object is returned from a function ( not a reference)
When the object is provided as a single argument to the same object's constructor
The copy constructor created a new copy of an object at a new memory location with identical
data member values. - answer-True
What happens if we copy an object that has a data member pointing to a location on the
heap? - answer-All of the above
3