What is the core idea of RAII (Resource Acquisition Is Initialisation) in C++?
Correct answer C. A resource is tied to an object's lifetime, acquired in its constructor and released in its destructor
With RAII, a class such as std::lock_guard, std::fstream or std::unique_ptr acquires a resource when constructed and releases it in its destructor. Because destructors run automatically when objects leave scope, including during exception unwinding, resources are freed reliably without manual cleanup code. C++ has no garbage collector; RAII is how it achieves deterministic cleanup.
Answer checked How we write and check questions
Discussion