Dynamic Memory Allocation

Use new and delete to manage memory during runtime.

// Allocate and deallocate an integer
int* p = new int;
*p = 42;
delete p;

// Allocate array
int* arr = new int[5];
delete[] arr;

Always pair new with delete to avoid memory leaks.

← PrevNext →