Section 4 : Constructors and Destructors, Dynamic memory management Flashcards

(7 cards)

1
Q

What is a constructor in C++?

A

A special function with the same name as the class, called automatically when an object is created. It has no return type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a default constructor?

A

A constructor with no parameters. Automatically created by C++ if no constructor is defined.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is constructor overloading?

A

Having multiple constructors in the same class, each with different parameter lists.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a copy constructor?

A

A constructor that creates a new object as a copy of an existing object. It takes a reference to another object of the same class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a destructor?

A

A special function that is automatically called when an object is destroyed. It starts with ~ and has no parameters or return type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the purpose of the :: scope resolution operator in C++?

A

The :: operator is used to access a variable or function from a specific scope, such as a class, namespace, or the global scope.

class MyClass {
public:
void show();
};

void MyClass::show() {
// Defined outside the class
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly