Exercise · References and Pointers · lesson 8 of 9
Exercise: min and max through references
Write a function void min_max(const int* data, int n, int& lo, int& hi). The pointer data points to the first of n numbers that lie in memory one after another. The function writes the smallest of these numbers to lo and the largest to hi.
- numbers
4 -2 9 0 7→lo == -2,hi == 9 - a single number
5→lo == 5,hi == 5 - numbers
-3 -1 -8→lo == -8,hi == -1
Constraints: n is at least 1, numbers may be negative and unsorted, and lo and hi may hold anything beforehand.
Do not add extra #include lines unless the task says so explicitly.
Subscribe to take the course
The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.