Correct Answers Updated 2024-2025
3 things normally done for classes with pointer member variables - Answer--include the
destructor in the class
-overload the assignment operator for the class
-include the copy constructor
Can you pass an object of a derived class to a formal parameter of the base class? -
Answer-yes
Static binding - Answer-necessary code to call a specific function generated by the
compiler... static or early binding
Dynamic binding - Answer-compiler does not generate code to call a specific function; it
generates information to enable run-time system to generate specific code for the
function call. (aka late binding)
Virtual functions have __ binding - Answer-binding occurs at program execution time,
not at compile time.... dynamic
Regardless of whether the object is passed by ref or val, if a derived class object is
passed to a formal parameter of the base class type, the destructor of __ executes -
Answer-the base class
Solution: - Answer-use a virtual destructor in the base class
The virtual destructor of a base class automatically makes the destructor of a ___ class
__ - Answer-derived... virtual
after executing the destructor of the derived class.. - Answer-the destructor of the base
class executes
the destructor of the derived class does not execute if it is not - Answer-virtual
if a base class contains virtual functions, make the destructor of the base class -
Answer-virtual
syntax for pure virtual functions - Answer-set them equal to 0
abstract class contain one or more ___ virtual functions - Answer-pure
, difference between virtual and pure virtual - Answer-pure virtual do not need to define
definition in base class.
the only built-in operations on classes are - Answer-assignment
member selection
is the statement int* p; equivalent to int *p; or int * p; - Answer-yes
in the stament int* p, q; both are pointers t/f - Answer-false
this is valid int *p, *q; - Answer-yes
* refers to the ___ to which its ___ points - Answer-object... operand
can you make a pointer that points to an object of another type like a struct - Answer-
yes
dot operator has a ___ precedence than dereferencing operator... solve this - Answer-
higher...
(*studentPtr).gpa = 3.9;
member access operator also in another form - Answer-->
syntax for accessing a class member using the operator is - Answer-
pointrVariableName->classMemberName
thus - Answer-Thus,
(*studentPtr).gpa = 3.9;
is equivalent to:
studentPtr->gpa = 3.9;
t/f Pointer variables must be initialized if you do not want them to point to anything -
Answer-true
a null pointer - Answer-p = 0; or p = NULL;
the number __ is the only number that can be directly assigned to a pointer variable -
Answer-0
new ___ and returns __ - Answer-allocates memory and returns a pointer to it's (starting
address)
create a pointer pointing to an array of 5 dynamically allocated chars called name. -
Answer-char *name;
name = new char[5];