Which statement best describes how memory is allocated for a static array?
Think about when the size of a static array is fixed and how that affects memory.
Static arrays have a fixed size determined at compile time, so their memory allocation is fixed and cannot change during program execution.
What typically happens when a dynamic array reaches its current capacity and a new element is added?
Consider how dynamic arrays manage to grow beyond their initial size.
Dynamic arrays allocate a bigger memory block, copy existing elements to it, and then add the new element to allow growth.
Which of the following best explains the difference in element access speed between static and dynamic arrays?
Think about how memory layout affects speed of accessing elements.
Static arrays store elements in a fixed, contiguous block of memory, allowing very fast access. Dynamic arrays also use contiguous memory but may occasionally reallocate, though access speed is generally similar. Fragmentation can affect dynamic arrays if not managed well.
Which statement correctly compares memory efficiency of static and dynamic arrays?
Consider how each array type handles unused space.
Static arrays allocate fixed memory exactly for their size, so no extra space is wasted. Dynamic arrays often allocate more space than needed to reduce the frequency of resizing, which can lead to some unused memory.
You are designing a real-time embedded system where predictable timing is critical. Which array type is more suitable and why?
Think about what matters most in real-time systems: timing predictability or flexibility.
Real-time systems require predictable timing. Static arrays have fixed size and memory, so access times are consistent and no delays occur from resizing, making them ideal for such systems.