how to initialize array with new in c++

#include <iostream>

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

    // Step 2: Use the 'new' keyword to dynamically allocate memory for the array
    arr = new int[5]; // You can replace '5' with the desired size of the array

    // Step 3: Initialize the array elements (optional)
    for (int i = 0; i < 5; ++i) {
        arr[i] = i * 2; // You can initialize the elements based on your requirements
    }

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

    // Step 5: Don't forget to free the dynamically allocated memory using 'delete'
    delete[] arr;

    return 0;
}