I'm learning about the lower_bound function in C++. To give an example, the author gives the following piece of code:
auto k = lower_bound(array,array+n,x)-array;
if (k < n && array[k] == x) {
// x found at index k
}
I understand that the type of k will be a pointer that holds the address of either the found value or the element after the last element in the array. I, however, don't fully understand the purpose of subtracting the array from the value we get from the lower_bound function. If someone could explain the purpose behind this, I'd really appreciate it. Thanks in advance.