Practice mode C++

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

Explanation

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.