Memory and RAII interview questions

15 Memory and RAII questions from the C++ bank, written for Indian campus drives and tech interviews. Every question has a verified answer and an AI-tutor explanation on placd.

Free to start: the 2-minute IT readiness check — six questions and a result.

Take the free IT readiness check

or take a mock interview set up for this area

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

Answer + AI explanation with Pro

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

Answer + AI explanation with Pro

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

Answer + AI explanation with Pro

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

Answer + AI explanation with Pro

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

Answer + AI explanation with Pro

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

Answer + AI explanation with Pro

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

Answer + AI explanation with Pro

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

Answer + AI explanation with Pro

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

Answer + AI explanation with Pro

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

Answer + AI explanation with Pro

11. Which term means: "a reference-counted smart pointer that deletes its managed object only when the last owner sharing the count is destroyed"?

Mid
  1. A.new expression
  2. B.std::shared_ptr
  3. C.RAII
  4. D.std::unique_ptr

Answer + AI explanation with Pro

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

Answer + AI explanation with Pro

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

Answer + AI explanation with Pro

14. Which term means: "a non-owning observer of a shared resource that does not affect the reference count and is used to break ownership cycles"?

Senior
  1. A.RAII
  2. B.new expression
  3. C.std::weak_ptr
  4. D.std::shared_ptr

Answer + AI explanation with Pro

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

Answer + AI explanation with Pro

Free to start

Start with a free readiness check

Sign up free for the 2-minute IT readiness check and a scored result. Answers, explanations and the AI tutor on every Memory and RAII question come with Pro.

Take the free IT readiness check

or take a mock interview set up for this area

24,000+ questions & coding problemsSoftware & IT16,274 questionsGovernment jobs26 examsAptitudenew questions every timeAI practice interviewwith feedback65 topics to practiseMechanical1,149 questionsGATE ME9 papersEngineering Mathematics381 questions2-minute checkfreeDSA Problems1,422Civil1,005 questionsGATE CE9 papersCS Fundamentals1,209 questionsYour scores6 skillsSystem Design25Electrical / EEE1,047 questionsGATE EE9 papersRun your codeC++ · Java · PythonLow-Level Design144Electronics & Comm.975 questionsGATE EC9 papersAI help on every questionFull-Stack6,282Chemical1,005 questionsGATE CH9 papersAI whiteboardsystem designWork abroadEurope · remote · transfersESE ME1 paperGATE practice papers2019–2026ESE CE1 paperDate alertsbefore the last dateESE EE1 paperBehavioural courseHR round practiceESE ET1 paperResume optimizerProSSC JE ME1 paperApplication trackerSSC JE CE1 paperCompany-wise prepSSC JE EE1 paperRole roadmapsRRB JE1 subjectPriced in ₹UPI · cardsISRO SC1 paperGATE CS9 papersIBPS SO IT1 paperUGC NET CS1 paperSSC CGL26 papersIBPS PO26 papersRRB NTPC26 papersSSC CHSL26 papersIBPS Clerk26 papersSBI Clerk26 papersRRB Group D26 papersSSC CPO26 papersSSC GD26 papers