Classes, Inheritance, and Object-Oriented Concepts in C++ Flashcards
(53 cards)
What command is used to link a C++ object file?
g++ MyClass.o -o MyProgram
What is the significance of the C++ Standard version 2020?
Introduced concepts and ranges
What feature does setw provide in C++?
Sets the width of the next output field
What does the using namespace std; statement do?
Allows access to the standard namespace
What is the principle of modularity in C++?
Code organized into classes/files
Define abstraction in the context of C++.
Hide unnecessary details
What does encapsulation mean in C++?
Private data, accessed only via class
What is extensibility in C++?
Reuse and build on top of existing code
Define polymorphism in C++.
Same interface, different behavior
What is inheritance in C++?
Child class inherits from parent class
What is the syntax to define a class in C++?
class ClassName { /* members */ };
What does a constructor do in C++?
Called automatically when an object is created
What is the role of a destructor in C++?
Called automatically when an object goes out of scope
How do you declare a parameterized constructor?
ClassName(int i, int j)
Fill in the blank: A parameterized constructor creates objects with _______.
Initial values
What is the rule for default parameters in C++?
Once a default is used, all following parameters must have one too!
What does the scope resolution operator :: do?
Defines class methods outside the class
True or False: You should use malloc() and free() in C++.
False
What is the correct way to allocate memory for an integer in C++?
int* p = new int(42);
What is the difference between a reference and a pointer in C++?
Reference: Implicit dereference; Pointer: * required
What is the syntax for passing by reference?
void function(int& x)
Fill in the blank: The this pointer is used to refer to the _______.
Current object inside its method
What is a copy constructor in C++?
Creates a new object from another existing one
Why is a custom copy constructor necessary?
Default copy = shallow copy (bad for pointers!)