Allocate and deallocate memory on the heap using 'new' and 'delete'.
In C++, memory for variables can be allocated in two main places: the stack and the heap. Stack allocation is the default for local variables within functions. It's fast and automatic—memory is allocated when the function is entered and deallocated when it exits. However, the stack has a limited size, and the lifetime of variables is tied to their scope. The heap (or free store) is a large pool of memory available to the programmer for dynamic allocation at runtime. This is useful when you don't know the amount of memory you need at compile time, or when you need an object to persist beyond the scope in which it was created. To allocate memory on the heap, you use the `new` operator, which returns a pointer to the allocated memory. For example, `int* ptr = new int;` allocates enough memory for one integer and stores its address in `ptr`. You can also allocate arrays: `int* arr = new int[10];`. The most critical part of using `new` is that you are responsible for deallocating the memory once you are finished with it. This is done using the `delete` operator. For a single object, you use `delete ptr;`. For an array, you must use the array form: `delete[] arr;`. If you forget to `delete` the memory, it becomes a memory leak. The program loses the pointer to that memory but the memory remains allocated, effectively lost until the program terminates.