void findMax(int arr[], int n, int* pToMax)
{
if (n <= 0)
return; // no items, no maximum!
int max = arr[0];
pToMax = &arr[0];
for (int i = 1; i < n; i++)
{
if (arr[i] > max)
{
max = arr[i];
pToMax = (arr+i);
}
}
}
int main()
{
int nums[4] = { 5, 3, 15, 6 };
int *ptr;
findMax(nums, 4, ptr);
cout << "The maximum is at address " << ptr << endl;
cout << "It's at index " << ptr - nums << endl;
cout << "Its value is " << *ptr << endl;
}
It shows some error. I don't understand. I need to change the findMax function only. I cannot change the main function
Is there anyone tho can explain me why?
Thank You!!^_^