Suggest an editImprove this articleRefine the answer for “How does a static array differ from a dynamic array?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)**A static array** gets its memory once at creation and cannot change size, while **a dynamic array** can change size at runtime, allocating memory on the heap as needed. **Key point:** a static array is fast and simple, while a dynamic array is flexible but sometimes spends time copying elements when it expands.Shown above the full answer for quick recall.Answer (EN)Image**A static array** and **a dynamic array** differ in **how and when memory is allocated to them** and **whether the array's size can change while the program is running**. --- ### **1. Static array** - The size is set **once, at creation time**. - Memory is allocated **in advance** (on the stack or in a fixed memory area). - The number of elements **cannot** be changed: if more is needed, a new array must be created. **Example (C):** ```c int a[5]; // an array of 5 elements ``` If a 6th element is needed, it's impossible to add one, the array has to be recreated. **Pros:** - Simple structure. - Fast access to elements. - No memory reallocations. **Cons:** - The size cannot be changed. - Extra memory may be wasted if allocated "with a margin". --- ### **2. Dynamic array** - The size can be **changed at runtime**. - Memory is allocated **on the heap** as needed. - On overflow, a new memory block is created and the elements are copied there. **Example (Python / C++):** ```python arr = [1, 2, 3] arr.append(4) # adding a new element ``` (In C++ it's `std::vector`, in Java it's `ArrayList`.) **Pros:** - Flexibility: you can add and remove elements. - The size grows automatically. **Cons:** - Sometimes all elements get **copied** during expansion (expensive in time). - Less predictable memory usage. --- ### **3. Visually** **Static:** ```javascript [ ][ ][ ][ ][ ] ← fixed size ``` **Dynamic:** ```javascript [ ][ ][ ] → (overflowed) → creates [ ][ ][ ][ ][ ][ ] and copies ``` --- **Summary:** > A static array is fixed in size, fast and simple. > A dynamic array is resizable and flexible, but sometimes spends time on memory reallocation.For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.