Skip to content

Latest commit

 

History

History
23 lines (17 loc) · 435 Bytes

memory_management_array_allocation.md

File metadata and controls

23 lines (17 loc) · 435 Bytes

Dynamic array allocation

  • delete[] is used to free an array memory
#include <iostream>

int main() {
    int staticArray[] = {1, 2, 3, 4, 5, 6};

    constexpr auto size = 10;
    int* dynamicArray = new int[size];
    for (int i = 0; i < size; ++i) {
        *(dynamicArray + i) = i * 10;
    }

    for (int i = 0; i < size; ++i) {
        std::cout << dynamicArray[i] << '\n';
    }

    delete[] dynamicArray;
}