Hi C++ Experts,

I am a novice C++ programmer and have a need to find the largest integer value and index in an array pass into a function. Below is the code that I have come up with but not sure whether there is better way to do this:

Code:
#include <algorithm>
#include <iostream>
using namespace std;

void print_largest_number(int[], int);

int main() {
	int arrayNum[] = { 23, 5, -10, 0, 0, 321, 1, 2, 99, 30, 321, 100 };
	size_t arraySize = sizeof(arrayNum) / sizeof(arrayNum[0]);
	print_largest_number(arrayNum, arraySize);
}

void print_largest_number(int array[], int size)
{
	sort(array, array + size);
	cout << "The largest value is " << array[size - 1] << endl;
	cout << "The array index of largest value is " << size - 1 << endl;
}
However, it fails to check for multiple maximum values & only use the 1st one found. I can do additional comparison on the sorted array to get the correct result but question whether this is a good solution. There are many different ways to achieve the same objectives. In other word, by taking advantage of using built-in sort function, I lose control of locating the initial largest value and having to do additional comparison afterward instead.

Likewise, I will have to find the largest value & index from an array of characters.

Your advice would be appreciated.
Thanks in advance,
George