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.
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?
A parser builds a heap-allocated char ** list of tokens and hands it to the caller. Some tokens are duplicated strings, and some are slices into a larger buffer. How would you design the ownership rules and cleanup path so the caller can safely filter or free the result without leaks or double frees?
Design a bounded queue in C++ for one producer thread and one consumer thread on the same machine, where millions of handoffs per second are expected and latency matters more than perfect generality. What invariants would your design need to preserve, and what synchronization and memory-safety issues would you pay closest attention to?
A C struct that mirrors a binary message works on your laptop but fails on a different CPU and is larger than expected in memory. How would you reason about the struct layout before deciding whether it should be used for direct I/O parsing?
In a C or C++ Unix program, you spawn a child process, redirect its stdin and stdout, and sometimes the parent hangs waiting for output that never arrives. What OS-level mistakes would you look for in how file descriptors are created, duplicated, and closed?
Unlock Full Question Bank
Get access to all 21 Language-Level Memory Management (C/C++/Rust) interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.