Assume the following functions
void func (int* p);
int main(){
int* arr = new Object[10];
int* obj = new Object;
func(arr);
func(obj);
return 0;
}
When you call the function for arr, does func() create a new pointer, p, that is a pointer to the first element of arr? And in that case, does p need to be deleted at the end of the function to prevent a memory leak?
When you call the function for obj, does func() create a new pointer, p, that needs to be deleted?
If func is now defined as void func(int*& p)
, will it still work for arrays?
I want to ensure that I don't create accidental memory leaks when I write code