new and delete (C++)

new allocates memory on the heap at runtime and returns a pointer to it, while delete frees that memory. Every new must be matched by exactly one delete, or…