What is the need of a destructor? Explain with the help of an example.
Answer / Sangh Priya Rahul
A destructor is needed to clean up any resources (like memory, files, network connections etc.) that an object acquired during its lifetime. An example would be deleting dynamically allocated memory in C++ when an object is destroyed or goes out of scope. For instance, consider a class `MyClass` with a pointer member `data`. The destructor can be used to free this memory:
```cpp
MyClass::~MyClass() {
delete[] data;
}
```
| Is This Answer Correct ? | 0 Yes | 0 No |
What is abstraction in c++?
What is the use of this pointer in c++?
wrong statement about c++ a)code removably b)encapsulation of data and code c)program easy maintenance d)program runs faster
What are the differences between new and malloc?
Array base access faster or pointer base access is faster?
When is a template better solution than a base class??
What is the operator in c++?
What are advantages of c++?
Are there any new intrinsic (built-in) data types?
There are 100 students in a class. The management keep information in two tables. Those two tables are given like Roll no Name Age 001 ABC 15 002 XYZ 14 and Roll No Subject Marks 001 Math 75 001 Physics 55 002 Math 68 001 Hindi 69 They want the information like this Roll No Name Hindi Physics Math Total 001 ABC 69 55 75 199 002 XYZ 68 74 84 226 And Roll No Suject Highest 001 Math 98 007 Physics 84 021 Hindi 74 All 275 All information is kept in structure in main memory. You have to find last two tables.
What is stoi in c++?
Differentiate between C and C++.