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.

MediumTechnical
62 practiced

Write a C function that removes every node with a target value from a singly linked list and returns the new head. The implementation should free removed nodes correctly and handle deleting the first node without special-case bugs.

MediumTechnical
62 practiced

A multithreaded worker becomes slower as you add more CPU cores, even though each thread mostly updates its own counter inside a shared status object. How would you investigate the slowdown, and what low-level effects might explain 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.

MediumTechnical
83 practiced

A loop like for (int i = 0; i <= n; ++i) was merged into a C code path where n is the number of valid array elements. The code sometimes works in testing and sometimes crashes in production. What makes this pattern dangerous in C, and how can it turn into a harder-to-debug memory bug than a simple out-of-bounds read?

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.