Local variables live on the stack and are freed automatically. new allocates on the heap — it persists until you delete it:
int* p = new int(42);
cout << *p; // 42
delete p; // free the memory — ALWAYS do this!
p = nullptr; // good practice
int* arr = new int[10];
arr[0] = 5;
delete[] arr; // note: delete[] for arrays, not delete
In modern C++, prefer unique_ptr / shared_ptr (covered in Chapter 9) over raw new/delete.
Write createArray(int size, int fillVal) that allocates a heap array of size ints, fills each with fillVal, and returns the pointer.
Click "Run" to execute your code.