0
0
C++programming~5 mins

Object lifecycle in C++ - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What are the main stages of an object's lifecycle in C++?
The main stages are: creation (when the object is made), usage (when the object is used), and destruction (when the object is removed and its memory freed).
Click to reveal answer
beginner
What happens during the construction of an object?
During construction, the object's memory is allocated and its constructor function runs to set up initial values or states.
Click to reveal answer
beginner
What is the role of a destructor in C++?
A destructor is a special function that runs automatically when an object is destroyed. It cleans up resources like memory or files the object used.
Click to reveal answer
intermediate
How does scope affect an object's lifecycle?
An object created inside a scope (like inside a function) is destroyed automatically when the scope ends, meaning its destructor is called then.
Click to reveal answer
intermediate
What is the difference between automatic and dynamic object lifecycles?
Automatic objects are created and destroyed automatically based on scope. Dynamic objects are created with new and must be manually destroyed with delete.
Click to reveal answer
When is an object's destructor called in C++?
AOnly when the program ends
BWhen the object is created
CWhen the program starts
DWhen the object goes out of scope or is deleted
Which keyword is used to create a dynamic object in C++?
Anew
Bcreate
Cmalloc
Dconstruct
What happens if you forget to delete a dynamic object?
AProgram crashes immediately
BObject is destroyed automatically
CMemory leak occurs
DDestructor runs twice
Which function is automatically called when an object is created?
ACopy
BConstructor
CMain
DDestructor
If an object is declared inside a function, when is it destroyed?
AWhen the function ends
BAt program start
CWhen the object is used
DNever
Explain the lifecycle of an object in C++ from creation to destruction.
Think about what happens when you make an object and when it disappears.
You got /6 concepts.
    Describe the difference between automatic and dynamic object lifecycles in C++.
    Consider how and when objects are created and destroyed.
    You got /5 concepts.