C array search with explicit length

An array parameter is adjusted to a pointer in a C function. The function does not automatically know how many elements are available, so length must be passed separately.

C
#include <stdio.h>
#include <assert.h>
int find(const int values[], int n, int target) {
    for (int i = 0; i < n; i++) {
        if (values[i] == target) return i;
    }
    return -1;
}
int main(void) {
    int values[] = {5, 2, 7};
    printf("%d\n", find(values, 3, 7));
    assert(find(values, 0, 7) == -1);
    assert(find(values, 3, 9) == -1);
    return 0;
}
Read the full lesson