Questions and CORRECT Answers
What is the key difference between a static variable and a global variable? A) They come from
different parts of memory, or B) They have different visibility. - CORRECT ANSWER - B
What operations will acquire memory from heap? (declaration, free, malloc, new) - CORRECT
ANSWER - malloc, new
If a function calls another function, the local variables in these two functions use the memory
from (different, the same) stack frame(s). - CORRECT ANSWER - different
What is the best way to delete an array created by "p = new StructType[size];" in C++? -
CORRECT ANSWER - delete[] p;
What memory must be garbage collected by a destructor? (_____ memory created by _____ (in
the same, outside) the class) - CORRECT ANSWER - heap, constructors, in the same
Java programmers do not need to do garbage collection because Java A) does not use heap
memory, or B) uses a system program to collect garbage. - CORRECT ANSWER - B
What is the best way of deleting a linked list of objects in C++? A) head = 0; or B) Use a loop to
delete every object in the linked list. - CORRECT ANSWER - B
If A is the base class and B is a class derived from A, then class A) A becomes a member in class
B, or B) B has all the members of class A. - CORRECT ANSWER - B
In the implementation of the getMax() function in the PriQueue class, we need to read and write
the variables "front" and "rear", which are defined as protected members in the base class Queue.
Are the functions in the derived class allowed to access the protected members in the base class?
- CORRECT ANSWER - yes
, The semantics of multiple inheritance becomes complex and error prone, if the base classes have
(members with different names, overlapped members). - CORRECT ANSWER - overlapped
members
If you want to create a linked list of Container nodes, which can contain Publication node, Book
node, Thesis node, and Report node, what type of pointer should be declared in the Container to
point to all these nodes? [A pointer to (Book, Publication) node] - CORRECT ANSWER -
Publication
Defining a virtual function in class means that the function A) can be redefined in its child
classes, or B) is an interface only and not allowed implementation. - CORRECT ANSWER -
A
Given the following class definition and the variable declaration:
class employee
char *name;
long id;
}
class manager {
employee empl;
char* rank;
}x
How do you set an x's employee's ID to 12345? - CORRECT ANSWER - x.empl.id = 12345;
If the relation between two C++ classes can be best described as "has-a" relation, we should A)
contain one class in the other (containment), or B) derive one class from the other (inheritance). -
CORRECT ANSWER - A