allocation an array with new cpp

#include <iostream>

int main() {
    // Step 1: Declare a pointer to int
    int* arr;

    // Step 2: Determine the size of the array
    int size = 5;

    // Step 3: Allocate memory for the array using new
    arr = new int[size];

    // Step 4: Check if memory allocation is successful
    if (arr != nullptr) {
        // Step 5: Initialize the array elements (optional)
        for (int i = 0; i < size; ++i) {
            arr[i] = i + 1;
        }

        // Step 6: Access and use the array as needed

        // Step 7: Deallocate the memory using delete
        delete[] arr;
    } else {
        std::cout << "Memory allocation failed." << std::endl;
    }

    return 0;
}