Memory and RAII interview questions

15 real Memory and RAII questions from the C++ bank, as asked in Indian campus drives and tech interviews. Every question has a verified answer and an AI-tutor explanation on placd — free to start.

1. What is new expression?

Junior
  1. A.a reference-counted smart pointer that deletes its managed object only when the last owner sharing the count is destroyed
  2. B.allocates an object on the free store and runs its constructor, returning a pointer that must later be released to avoid a leak
  3. C.a non-owning observer of a shared resource that does not affect the reference count and is used to break ownership cycles
  4. D.a technique that ties resource acquisition to object construction and release to destruction, guaranteeing cleanup when scope exits even on exceptions
Reveal the answer + AI explanation — free account

2. Which term means: "allocates an object on the free store and runs its constructor, returning a pointer that must later be released to avoid a leak"?

Junior
  1. A.std::weak_ptr
  2. B.std::shared_ptr
  3. C.new expression
  4. D.std::unique_ptr
Reveal the answer + AI explanation — free account

3. Which statement is correct?

Junior
  1. A.new expression — allocates an object on the free store and runs its constructor, returning a pointer that must later be released to avoid a leak
  2. B.new expression — a non-owning observer of a shared resource that does not affect the reference count and is used to break ownership cycles
  3. C.new expression — a technique that ties resource acquisition to object construction and release to destruction, guaranteeing cleanup when scope exits even on exceptions
  4. D.new expression — a reference-counted smart pointer that deletes its managed object only when the last owner sharing the count is destroyed
Reveal the answer + AI explanation — free account

4. What is RAII?

Junior
  1. A.allocates an object on the free store and runs its constructor, returning a pointer that must later be released to avoid a leak
  2. B.a non-owning observer of a shared resource that does not affect the reference count and is used to break ownership cycles
  3. C.a reference-counted smart pointer that deletes its managed object only when the last owner sharing the count is destroyed
  4. D.a technique that ties resource acquisition to object construction and release to destruction, guaranteeing cleanup when scope exits even on exceptions
Reveal the answer + AI explanation — free account

5. Which term means: "a technique that ties resource acquisition to object construction and release to destruction, guaranteeing cleanup when scope exits even on exceptions"?

Junior
  1. A.std::unique_ptr
  2. B.RAII
  3. C.std::weak_ptr
  4. D.std::shared_ptr
Reveal the answer + AI explanation — free account

6. Which statement is correct?

Junior
  1. A.RAII — a non-owning observer of a shared resource that does not affect the reference count and is used to break ownership cycles
  2. B.RAII — a technique that ties resource acquisition to object construction and release to destruction, guaranteeing cleanup when scope exits even on exceptions
  3. C.RAII — a move-only smart pointer expressing exclusive ownership that automatically deletes its managed object and cannot be copied
  4. D.RAII — allocates an object on the free store and runs its constructor, returning a pointer that must later be released to avoid a leak
Reveal the answer + AI explanation — free account

7. What is std::unique_ptr?

Mid
  1. A.a move-only smart pointer expressing exclusive ownership that automatically deletes its managed object and cannot be copied
  2. B.allocates an object on the free store and runs its constructor, returning a pointer that must later be released to avoid a leak
  3. C.a reference-counted smart pointer that deletes its managed object only when the last owner sharing the count is destroyed
  4. D.a technique that ties resource acquisition to object construction and release to destruction, guaranteeing cleanup when scope exits even on exceptions
Reveal the answer + AI explanation — free account

8. Which term means: "a move-only smart pointer expressing exclusive ownership that automatically deletes its managed object and cannot be copied"?

Mid
  1. A.std::unique_ptr
  2. B.std::shared_ptr
  3. C.new expression
  4. D.std::weak_ptr
Reveal the answer + AI explanation — free account

9. Which statement is correct?

Mid
  1. A.std::unique_ptr — a non-owning observer of a shared resource that does not affect the reference count and is used to break ownership cycles
  2. B.std::unique_ptr — a reference-counted smart pointer that deletes its managed object only when the last owner sharing the count is destroyed
  3. C.std::unique_ptr — allocates an object on the free store and runs its constructor, returning a pointer that must later be released to avoid a leak
  4. D.std::unique_ptr — a move-only smart pointer expressing exclusive ownership that automatically deletes its managed object and cannot be copied
Reveal the answer + AI explanation — free account

10. What is std::shared_ptr?

Mid
  1. A.a non-owning observer of a shared resource that does not affect the reference count and is used to break ownership cycles
  2. B.a technique that ties resource acquisition to object construction and release to destruction, guaranteeing cleanup when scope exits even on exceptions
  3. C.a reference-counted smart pointer that deletes its managed object only when the last owner sharing the count is destroyed
  4. D.allocates an object on the free store and runs its constructor, returning a pointer that must later be released to avoid a leak
Reveal the answer + AI explanation — free account

12. Which statement is correct?

Mid
  1. A.std::shared_ptr — a non-owning observer of a shared resource that does not affect the reference count and is used to break ownership cycles
  2. B.std::shared_ptr — a reference-counted smart pointer that deletes its managed object only when the last owner sharing the count is destroyed
  3. C.std::shared_ptr — a technique that ties resource acquisition to object construction and release to destruction, guaranteeing cleanup when scope exits even on exceptions
  4. D.std::shared_ptr — a move-only smart pointer expressing exclusive ownership that automatically deletes its managed object and cannot be copied
Reveal the answer + AI explanation — free account

13. What is std::weak_ptr?

Senior
  1. A.a move-only smart pointer expressing exclusive ownership that automatically deletes its managed object and cannot be copied
  2. B.a technique that ties resource acquisition to object construction and release to destruction, guaranteeing cleanup when scope exits even on exceptions
  3. C.allocates an object on the free store and runs its constructor, returning a pointer that must later be released to avoid a leak
  4. D.a non-owning observer of a shared resource that does not affect the reference count and is used to break ownership cycles
Reveal the answer + AI explanation — free account

15. Which statement is correct?

Senior
  1. A.std::weak_ptr — a move-only smart pointer expressing exclusive ownership that automatically deletes its managed object and cannot be copied
  2. B.std::weak_ptr — allocates an object on the free store and runs its constructor, returning a pointer that must later be released to avoid a leak
  3. C.std::weak_ptr — a technique that ties resource acquisition to object construction and release to destruction, guaranteeing cleanup when scope exits even on exceptions
  4. D.std::weak_ptr — a non-owning observer of a shared resource that does not affect the reference count and is used to break ownership cycles
Reveal the answer + AI explanation — free account

Free to start

Answers, AI explanations, and a scored voice mock interview

Sign up free to check your answers with explanations, ask the AI tutor anything on any question, and take one full AI mock interview — scored like a real panel.

Practice Memory and RAII free