Trying to do the following task: Write a function that accepts an int array and the array size as arguments. The function should dynamically create a new array that is the same size as the array passed in. Each element in the new array should be double the corresponding element in the array passed in. Return a pointer to the new array.
E.g. if you pass in the array {2, -3, 5} of size 3, it should create a new array of size 3 with values {4, -6, 10} and return a pointer to it.
But got this error "a value of type "int *" cannot be assigned to an entity of type "int" on line 19.
Can someone explain it to me and how to fix it?
@siid14. L21 you are deleting the allocated memory and then returning it as a pointer! No. You are returning a pointer to now unallocated memory. The delete should be in the calling function after the memory has been used.
It is also easier to use std::unique_ptr as this doesn't require explicit deletion: