I don't know what you are seeing but fillarray is wrong. It returns the address of a local object that is deleted after that function ends. That data was on the stack, and the stack changes all the time, so likely it looks as if the array's data changed, but in reality, its undefined behavior due to a bad pointer and anything could happen.
If you want to ensure that arr is unchanged in MinMax(), declare it const. As in:
void MinMax(constint* arr)
However, that's not your problem.
This is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
int main() {
int* arr = FillArray(); // where does arr live, if we're returning a pointer to it?
MinMax(arr);
}
int* FillArray()
{
int arr[100]; // create a local array on the stack
// do stuff with it
return arr; // return a pointer to my array on the stack
// when we return, the memory under the stack is reused
// we have a pointer to junk
}
Always, with pointers, we need to know what we're pointing to.