Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Document preview thumbnail
Preview 4 out of 43 pages
Exam (elaborations)

CSE 240 FINAL EXAM MOCK TEST WITH ANSWER RATIONALES 2026

Document preview thumbnail
Preview 4 out of 43 pages

CSE 240 FINAL EXAM MOCK TEST WITH ANSWER RATIONALES 2026

Content preview

CSE 240 FINAL EXAM MOCK TEST WITH
ANSWER RATIONALES 2026

◉ Which C/C++ operations will acquire memory from heap? Select
all that apply.
Answer: - new
- malloc


◉ You do not need to garbage-collect the memory, if it comes from
(Select all that apply)
Answer: - global memory
- stack memory
- static memory


◉ What is the key difference between a static variable and a global
variable?
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.
Answer: k, m, j


◉ What is the best way of deleting an array created by "p = new
StructType[size];" in C++?
Answer: delete[] p;


◉ What memory must be garbage-collected by a destructor?
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++?

,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?
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?
Answer: Yes, always.


◉ If a class needs to inherit from multiple parent classes, the parent
classes must
Answer: be inherited as virtual classes.


◉ Defining a virtual function in class means that the function
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
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?
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?
Answer: dynamic_cast


◉ It does not cause memory (storage) overhead to create multiple
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?
Answer: It saves the word Hello into a file in the file system.

Document information

Uploaded on
August 25, 2026
Number of pages
43
Written in
2026/2027
Type
Exam (elaborations)
Contains
Questions & answers
CA$22.95

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
TopGradeInsider
4.2
(13)
Sold
165
Followers
2
Items
55375
Last sold
9 hours ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions