Explain C++ memory, types, and concurrency fundamentals

Quick Overview

Explain C++ memory, types, and concurrency fundamentals evaluates engineering fundamentals, trade-offs, examples, pitfalls, and operational implications in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.

Explain C++ memory, types, and concurrency fundamentals

Company: Sunrise

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: easy

Interview Round: Onsite

# Explain C++ memory, types, and concurrency fundamentals Answer the following C++ / systems fundamentals questions: 1) **C++ `class` vs `struct`** - What are the differences between `class` and `struct` in C++? - Can a `class` have a reference (`T&`) as a data member? What are the implications? 2) **Virtual constructor** - Can a constructor be `virtual` in C++? If not, what patterns achieve “polymorphic construction”? 3) **Pointer vs reference** - What are the key differences between pointers and references in C++ (nullability, reseating, object lifetime, ABI, usage)? 4) **Placement new** - What is placement `new`? When would you use it, and what must you do manually after using it? 5) **Performance comparison (cache/memory effects)** - Compare likely performance and CPU/memory behavior of these two loops (assume `data` points to a large `int` array of length `64*1024*1024` allocated on the heap): - Code A: increment `data[0]` in a tight loop `N` times. - Code B: increment `data[i]` for `i = 0; i < N; i += 8`. - Discuss caching, prefetching, write allocation, store buffers, memory bandwidth, and why one might be faster. 6) **Function pointer type** - In `int (*s[10])(int);`, what is the type of `s`? 7) **`unordered_map` vs `map`** - Compare complexity guarantees, ordering, iterator invalidation, memory overhead, and typical use cases. 8) **Overloading vs overriding** - Explain function overloading vs method overriding (virtual dispatch) in C++. 9) **Mutex vs condition variable** - What problems does each solve? Why do condition variables require a mutex and a loop around `wait`? 10) **What causes a physical memory access?** - At a high level, what events force the CPU to access DRAM (vs cache)? Include page faults, TLB misses, cache misses, and DMA. 11) **Shared memory synchronization** - If multiple processes/threads communicate via shared memory, how do you correctly synchronize access? Discuss options (process-shared mutexes, semaphores, futexes, file locks) and pitfalls. 12) **Linux networking and virtualization (high level)** - Describe how a packet travels through the Linux networking stack, and how common virtualization primitives (namespaces, veth pairs, bridges, TAP, iptables/nftables) fit into that path. ### Clarifying Questions to Ask - Clarify language/runtime assumptions and the level of depth expected. - Use examples to connect definitions to practical engineering decisions. - Call out pitfalls, trade-offs, and common misconceptions. ### What a Strong Answer Covers - Accurate definitions and comparisons with concrete examples. - Complexity, lifecycle, safety, or operational implications where relevant. - Trade-offs that explain when one approach is preferable to another. - Common failure modes and how to avoid them. ### Follow-up Questions - How would you debug a production issue related to this topic? - What trade-off would change in a high-throughput service? - Which misconception do candidates often have here?

Quick Answer: Explain C++ memory, types, and concurrency fundamentals evaluates engineering fundamentals, trade-offs, examples, pitfalls, and operational implications in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.

|Home/Software Engineering Fundamentals/Sunrise
Sunrise logo
Sunrise
Jul 21, 2025, 12:00 AM
easySoftware EngineerOnsiteSoftware Engineering Fundamentals
1
0

Explain C++ memory, types, and concurrency fundamentals

Answer the following C++ / systems fundamentals questions:

  1. C++ class vs struct
  • What are the differences between class and struct in C++?
  • Can a class have a reference ( T& ) as a data member? What are the implications?
  1. Virtual constructor
  • Can a constructor be virtual in C++? If not, what patterns achieve “polymorphic construction”?
  1. Pointer vs reference
  • What are the key differences between pointers and references in C++ (nullability, reseating, object lifetime, ABI, usage)?
  1. Placement new
  • What is placement new ? When would you use it, and what must you do manually after using it?
  1. Performance comparison (cache/memory effects)
  • Compare likely performance and CPU/memory behavior of these two loops (assume data points to a large int array of length 64*1024*1024 allocated on the heap):
    • Code A: increment data[0] in a tight loop N times.
    • Code B: increment data[i] for i = 0; i < N; i += 8 .
  • Discuss caching, prefetching, write allocation, store buffers, memory bandwidth, and why one might be faster.
  1. Function pointer type
  • In int (*s[10])(int); , what is the type of s ?
  1. unordered_map vs map
  • Compare complexity guarantees, ordering, iterator invalidation, memory overhead, and typical use cases.
  1. Overloading vs overriding
  • Explain function overloading vs method overriding (virtual dispatch) in C++.
  1. Mutex vs condition variable
  • What problems does each solve? Why do condition variables require a mutex and a loop around wait ?
  1. What causes a physical memory access?
  • At a high level, what events force the CPU to access DRAM (vs cache)? Include page faults, TLB misses, cache misses, and DMA.
  1. Shared memory synchronization
  • If multiple processes/threads communicate via shared memory, how do you correctly synchronize access? Discuss options (process-shared mutexes, semaphores, futexes, file locks) and pitfalls.
  1. Linux networking and virtualization (high level)
  • Describe how a packet travels through the Linux networking stack, and how common virtualization primitives (namespaces, veth pairs, bridges, TAP, iptables/nftables) fit into that path.

Clarifying Questions to Ask Guidance

  • Clarify language/runtime assumptions and the level of depth expected.
  • Use examples to connect definitions to practical engineering decisions.
  • Call out pitfalls, trade-offs, and common misconceptions.

What a Strong Answer Covers Guidance

  • Accurate definitions and comparisons with concrete examples.
  • Complexity, lifecycle, safety, or operational implications where relevant.
  • Trade-offs that explain when one approach is preferable to another.
  • Common failure modes and how to avoid them.

Follow-up Questions Guidance

  • How would you debug a production issue related to this topic?
  • What trade-off would change in a high-throughput service?
  • Which misconception do candidates often have here?
Loading comments...