Important prelude: If you can, using vector instead of arrays/pointers. We would all encourage this as much as possible! It's quite possible to program for months on end, writing some quite complex software, and never have to call new or delete and never have to worry about all those nasty C problems.
Just stop using temp!
void nothing(int* buffer)
{
for (int i = 0; i < 5; i++)
{
buffer[i] = i;
}
}
This will take, as input, a pointer to your array. And it will then write directly to that array.
Your earlier code created a second array. Every time you call new you get a new array. int* temp = new int[5];. For this approach to work you would need to copy data in the temp array to the buffer array. But, you can't copy arrays (easily) in C.
buffer = temp; // This *doesn't* copy any array
This line did nothing. The two arrays still exist, and no data was copied as a result of this. The local variable called buffer was modified here ; but the change was minor -- buffer used to point at the old array and now it points at the new array. And because buffer was a local variable, it lost all meaning as soon as the function returned (it pointed to non-local data, but the buffer pointer itself is still local.
In shorty, your original nothing function did nothing useful. It created a new array, put some values into it, then it ignored it. The buffer variable inside main was not affected by your function.