Exercise · References and Pointers · lesson 8 of 8
Exercise: find an element, return a pointer
Write a function const int* find_value(const int* data, int n, int value). The pointer data points to the first of n numbers that lie in memory one after another. The function returns a pointer to the first of these numbers that equals value, or nullptr if there is no such number.
- numbers
4 7 1 7 9,valueis1→&data[2] - numbers
4 7 1 7 9,valueis7→&data[1] - numbers
4 7 1 7 9,valueis5→nullptr
Constraints: the value can be at any position and occur more than once; n may be 0, and then the function returns nullptr.