also in the first program there is no memory leak.
Are you sure. His program is tricky in a sense that there is a memory
leak. His function is definitely not doing what he thinks its doing.
One way to tell if you have memory leak is to see if every new
is matched with delete. In your function, you allocate new memory for the array
that is passed, which already has been allocated memory. So when
inside the function, the arrays thats passed is located in whatever
memory address that was reserved inside the function. When he
exits out that functions, that memory is no longer in play. Inside
main he has already the array pointing at a specific address.
So the memory inside the function has a leak. Also you use
2 instances of new but only 1 delete. Does that give you a hint?