heap allocated array in c ++
#include <iostream>
int main() {
// Step 1: Declare a pointer to int
int *arr;
// Step 2: Allocate memory on the heap for an array of 5 integers
arr = new int[5];
// Step 3: Initialize the elements of the array
for (int i = 0; i < 5; ++i) {
arr[i] = i * 10;
}
// Step 4: Access and print the elements of the array
for (int i = 0; i < 5; ++i) {
std::cout << "arr[" << i << "] = " << arr[i] << std::endl;
}
// Step 5: Deallocate the memory allocated on the heap
delete[] arr;
return 0;
}