InterviewStack.io LogoInterviewStack.io

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

How specific languages expose and manage memory: pointers and references, pointer arithmetic, stack versus heap allocation, ownership and borrowing in Rust, RAII and smart pointers in C++, manual allocation and freeing in C, and garbage-collection semantics as a language feature. Covers reasoning about ownership, lifetimes, leaks, and dangling references at the language level. OS-level virtual memory and paging internals live in Operating Systems & Systems Programming.

HardTechnical
90 practiced

You have a hot loop that processes tens of millions of fixed-size records and spends most of its time on CPU, not I/O. If algorithmic complexity cannot change, what measurements and code changes would you consider to improve throughput?

MediumTechnical
68 practiced

A library function allocates a buffer, returns it to the caller, and another layer later frees it. After a refactor, some paths free the buffer twice and other paths leak it. How would you redesign the interface contract so ownership is obvious and hard to misuse?

EasyTechnical
132 practiced

A C function in a service occasionally crashes when a caller uses the pointer it returns, but only after the function has finished executing. How would you debug this, and what would you look for in the code and runtime behavior to confirm the root cause?

EasyTechnical
69 practiced

You're designing an in-memory index in C++ that stores millions of small objects. Some objects are short-lived, others stay alive for the entire process. How would you decide where to allocate them, and what trade-offs would matter most for latency, fragmentation, and cache locality?

MediumTechnical
61 practiced

A teammate replaced a byte-by-byte read with a cast from uint8_t * to uint32_t * to speed up parsing. The code passes unit tests on one platform but breaks under optimization on another. What concerns would you raise, and how would you prove whether the cast is safe or whether the optimization is relying on undefined behavior?

Unlock Full Question Bank

Get access to all 20 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.