Functions often need to return multiple values. Pairs and tuples make this clean. Return a pair: pair<int, int> minMax(vector& v) { return {*min_element(v.begin(), v.end()), *max_element(v.begin(), v.end())}; } Call it with structured bindings: auto [lo, hi] = minMax(nums); Now lo has the minimum and hi has the maximum.
For more than two values, use tuple or define a struct. Structs are better when the returned values have clear names and you'll use them in many places.