NewWork mode: your Claude Code or Codex on work calls, answering from your project's codeSkip to content

Quiz: C/C++

C/C++ questions from real interviews as a quiz, with an explanation for every option.

31 questionsAll topicsC/C++

Try it: 5 questions

Loading…

Sample questions

  1. Which approaches help prevent deadlocks when working with multiple mutexes? Select all that apply.

    • Do not hold one mutex while waiting to acquire another
    • Use std::lock to acquire several mutexes together
    • Always acquire mutexes in the same order
    • Periodically detect deadlocks after they have occurred
    • Set an acquisition timeout but keep holding mutexes already acquired
    Full answer
  2. Which statement about the size of an empty class object in C++ is correct?

    • The standard requires sizeof to always be 1 byte.
    • sizeof is usually 1 byte, but the standard does not specify the exact size.
    • sizeof is always 0 because the class has no fields.
    • The size is always the size of a pointer so the object has a unique address.
    Full answer
  3. Which statement best describes functional programming?

    • Programs are built around functions, while mutation and side effects are kept to a minimum.
    • Programs are built around objects that combine state with methods for changing it.
    • Programs consist of commands that change shared variables in sequence.
    • Programs must use recursion instead of loops and completely avoid input and output.
    Full answer
  4. Which option best describes the typical path from entering a URL to loading a page?

    • The browser parses the HTML and displays the page, then establishes a connection and requests the remaining data.
    • The browser parses the URL, resolves the IP via DNS if needed, establishes a connection, sends an HTTP request, and processes the response to display the page.
    • The browser resolves the IP via DNS, sends an HTTP request, then establishes a TCP connection and performs the TLS handshake.
    • The browser sends an HTTP request first, looks up the IP via DNS next, and establishes a connection only after the server responds.
    Full answer
  5. Which statement correctly describes atomic operations and memory_order in C++?

    • Atomicity synchronizes all operations in a thread, while memory_order selects the size of the atomic value.
    • Every atomic operation automatically synchronizes with all atomic operations in other threads.
    • An atomic operation is indivisible to other threads, while memory_order specifies guarantees for ordering and visibility across threads.
    • memory_order makes an operation indivisible, while the atomic type determines the order in which changes become visible.
    Full answer
  6. Which mapping of protocols to OSI layers is correct?

    • HTTP — data link, TCP — transport, IP — session
    • HTTP — application, TCP — transport, IP — network
    • HTTP — network, TCP — application, IP — transport
    • HTTP — transport, TCP — network, IP — application
    Full answer
  7. What is a memory leak in programming?

    • Allocated memory is no longer needed but is not freed and remains occupied.
    • The program allocates memory and frees it immediately after use.
    • The program accesses memory after it has been freed.
    • The program allocates more memory than a current operation requires.
    Full answer
  8. What is usually called a bucket in a hash table?

    • A memory region allocated only for the hash value itself
    • A counter for the total number of collisions in the table
    • A function that converts a key into an array index
    • A group of elements mapped to the same slot by hashing
    Full answer
  9. What requirements must you satisfy to use a custom type as a key in std::map or std::unordered_map? Select all that apply.

    • Ensure that keys considered equal have the same hash value.
    • Provide std::map with a comparator that defines a strict weak ordering.
    • Provide std::unordered_map with a comparator that orders keys.
    • Provide std::map with a hash function and an equality check.
    • Provide std::unordered_map with a hash function and an equality check.
    Full answer
  10. Which statements about a process's address space and executable size are generally true? Select all that apply.

    • Initialized global data usually goes into .data, and its initial values are stored in the executable file.
    • Typical regions include code and constants, global data, the heap, the stack, and memory-mapped files.
    • Global variables are usually placed on the stack, and their initial values are created on each function call.
    • The .bss region usually stores zero bytes in the file, so its size directly increases the executable's size.
    • Uninitialized or zero-initialized global data usually goes into .bss; the loader allocates and zeroes this region.
    Full answer