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
67 practiced

A production C service occasionally corrupts heap memory after handling a few large requests, but you cannot reproduce it with a single test case. How would you narrow down the source of the corruption and what would you instrument first to catch it in the act?

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?

EasyTechnical
73 practiced

A C function stores the address of a temporary local array inside a struct field, returns the struct, and the program later crashes when that field is read. What is happening at the memory level, how would you spot this in a code review, and what ownership rule would you change in the API to prevent it?

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?

MediumTechnical
64 practiced

Implement in C a function with this signature: int append_int(int **data, size_t *len, size_t *cap, int value). It should grow a heap array when needed, preserve existing elements, and leave the original allocation unchanged if growth fails. Walk through the code or write it.

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.