Language-Level Memory Management (C/C++/Rust) Questions

How C and C++ expose and manage memory at the language level: pointers and pointer arithmetic, pointers to pointers and function pointers, arrays versus pointers and array decay, stack versus heap storage, manual allocation and freeing in C (malloc, realloc, free), new and delete versus malloc and free, placement new, RAII and owning smart pointers (unique_ptr, including custom deleters for C resources), shallow versus deep copies and move semantics in C++. Covers reasoning about who owns a buffer and designing ownership and lifetime contracts across function, library and plugin boundaries; dangling and uninitialized pointers, leaks, double frees, use-after-free, off-by-one errors and buffer overruns and how to prevent them; undefined behavior, strict aliasing and safe byte reinterpretation, endianness; struct layout, alignment and padding as the language defines them; and finding and diagnosing memory bugs with sanitizers, Valgrind-style tools, tracing allocators and heap-corruption triage, including allocator design and heap fragmentation at the language level. Boundary: garbage-collector behavior and tuning, embedded memory budgets, register access and packing structs to hardware layouts, OS virtual memory and paging, and lock-based concurrency are covered elsewhere.

HardTechnical
81 practiced

Explain C++ move semantics and rvalue references. When does a value get moved instead of copied, what state is a moved-from object in, and what pitfalls (returning references to temporaries, misusing std::move) lead to dangling references?

MediumTechnical
112 practiced

What is strict aliasing in C and C++, and why can violating it cause bugs that appear only under optimization? What idioms do you use to inspect or reinterpret raw bytes safely?

EasyTechnical
115 practiced

How does an array differ from a pointer in C, particularly when passed to a function? Why does array-to-pointer decay lead to length-handling and bounds-check bugs, and what does sizeof return in each case?

EasyTechnical
118 practiced

In C or C++, what is the difference between stack and heap memory, what does each mean for an object's lifetime, and when does the distinction cause bugs such as stack overflow or leaks?

HardSystem Design
130 practiced

You are designing a general-purpose memory allocator for a multithreaded C or C++ program. How would you use per-thread caches, size classes, and a shared free list, and how do you keep fragmentation and contention low while handling frees that arrive on a different thread than the allocating one?

Unlock Full Question Bank

Get access to all 14 Language-Level Memory Management (C/C++/Rust) interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.