Stack vs Heap: Memory Made Simple Quiz

  1. Call Frames and Locals

    Which memory region stores function call information and local variables when a function like add(a, b) is invoked?

    1. Stack
    2. Heap
    3. Global data area
    4. Disk buffer
    5. Stak
  2. Dynamic Size at Runtime

    When you read a number n from the user and then allocate an array of n integers at runtime, where is that memory typically taken from?

    1. Heap
    2. Stack
    3. CPU registers
    4. Const segment
    5. Heep
  3. Local Variable Lifetime

    What typically happens to a local variable defined inside a function after the function returns, such as int x = 5 inside foo?

    1. Its storage is automatically reclaimed when the stack frame is removed.
    2. It persists for the entire program even after the function returns.
    3. It moves to the heap automatically when the function ends.
    4. It becomes a global constant after the first assignment.
    5. It is saved to disk and reloaded on the next call.
  4. Allocation Speed

    For short-lived data such as a small temporary struct inside a function, which kind of allocation is generally faster?

    1. Stack allocation (push/pop)
    2. Heap allocation via allocator
    3. Disk paging
    4. Network buffer allocation
    5. Stak allocaton
  5. Thread-Local Storage

    In a multithreaded program where two threads each call a function with a local variable counter, where are those counters stored?

    1. On each thread's own stack
    2. In a single shared heap only
    3. In the CPU cache exclusively
    4. In the global constant area
    5. On the main thread's stack only
  6. Fragmentation Risk

    Which memory area is more prone to external fragmentation after many allocations and frees over time in a long-running program?

    1. Heap
    2. Stack
    3. Register file
    4. ROM
    5. Heeap
  7. Returning Addresses

    Why is returning the address of a local variable (for example, return u0026temp) considered a bug in many languages?

    1. Because the pointer refers to stack memory that is reclaimed after return
    2. Because pointers cannot be returned from functions at all
    3. Because heap memory is always faster than stack memory
    4. Because it always leaks memory by design
    5. Because local variables are stored in ROM and cannot be addressed
  8. Big Objects

    Which memory area is typically larger and suitable for storing big objects like a 10,000-element array created at runtime?

    1. Heap
    2. Stack
    3. CPU registers
    4. Instruction cache
    5. Static call stack
  9. Recursion Limits

    What is a common risk of extremely deep or infinite recursion, such as a function calling itself without a proper base case?

    1. Stack overflow due to running out of stack space
    2. Heap defragmentation
    3. Disk fragmentation
    4. CPU overheating
    5. Heep underflow
  10. Heap Lifetime

    Which statement best describes the lifetime of heap-allocated memory obtained via a dynamic allocation call?

    1. It remains allocated until it is explicitly freed or reclaimed by a runtime, not automatically at function return.
    2. It is always freed when the creating function returns.
    3. It becomes read-only exactly one second after allocation.
    4. It is automatically saved to disk at program exit and reloaded next run.
    5. It converts into stack memory after the first use.