and CORRECT Answers
If a function calls another function, the local variables in these two functions use the memory
from - CORRECT ANSWER - different stack frames.
Which C/C++ operations will acquire memory from heap? Select all that apply. - CORRECT
ANSWER - - new
- malloc
You do not need to garbage-collect the memory, if it comes from (Select all that apply) -
CORRECT ANSWER - - global memory
- stack memory
- static memory
What is the key difference between a static variable and a global variable? - CORRECT
ANSWER - They have different visibility.
Given the snippet of code:
int x = 5;
int bar(int j)
{
int *k = 0, m = 5;
k = &m;
return (j+m);
}
void main(void)
{
static int i =0;
,i++;
i = bar(i) + x;
}
Which variables obtain their memory from the stack? Select all that apply. - CORRECT
ANSWER - k, m, j
What is the best way of deleting an array created by "p = new StructType[size];" in C++? -
CORRECT ANSWER - delete[] p;
What memory must be garbage-collected by a destructor? - CORRECT ANSWER - heap
memory created in the constructors in the same class
What is the best way of deleting a linked list of objects in C++? - CORRECT ANSWER - Use
a loop to delete every object in the linked list.
What is the best way of deleting all the nodes in a binary tree pointed to by the root pointer? -
CORRECT ANSWER - Traverse the tree and delete each node individually.
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, always.
If a class needs to inherit from multiple parent classes, the parent classes must - CORRECT
ANSWER - be inherited as virtual classes.
Defining a virtual function in class means that the function - CORRECT ANSWER - can be
redefined in its child classes.
, If you declare a pointer to the object of the parent class and use the pointer to access the object of
a child class, you can access - CORRECT ANSWER - the members that exist in the parent
class.
Assume that Publication is the root class of an inheritance tree. You want to form a linked list of
different publications in the inheritance tree, including Book, Report, Newspaper, etc. What is
the best way to create a linked list using PublListNode and Publication classes? - CORRECT
ANSWER - The PublListNode class contains the Publication class.
What type casting mechanism should be used if you want to change pointer type for pointing to a
different object in an inheritance hierarchy? - CORRECT ANSWER - dynamic_cast
It does not cause memory (storage) overhead to create multiple - CORRECT ANSWER -
names (alias) for a variable.
Given the following snippet of C++ code:
string name = "Hello";
ofstream myFile;
myFile.open(myFile);
myFile << name;myFile.close();
What does it do? - CORRECT ANSWER - It saves the word Hello into a file in the file
system.
The exception handling mechanism discussed in this course is at the level of - CORRECT
ANSWER - user program.
A throw statement is associated with a specific exception handler through the - CORRECT
ANSWER - the data type implied by the throw value.
There are various consequences to not using the C++ built-in exception handling mechanisms.
Which of them is the most serious consequence? - CORRECT ANSWER - Not restoring the
stack pointer to its original position before entering the function.