hey guys, i have a problem with this program...
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;
}
i know that the problem is that the compiler is outputting the memory address and not the actual value that i want it to output. how would i change that?
thanks guys