Repair first-occurrence linear search

The fragment is meant to return the first index containing target, or -1 if absent, for lengths 0 through 8. Identify three independent defects and repair them. Do not execute the broken fragment or assign it a reliable output. Then write a complete test driver: input is n, n integer elements, then target, separated by whitespace; element and target values lie in [-100,100]. Print only the returned index and a newline. For the named duplicate sample, input is 5 / 8 3 8 2 8 / 8 (slashes denote line breaks). Explain the empty-array and absent-target cases.

int find_first(const int a[], int n, int target) {
    int answer = 0;
    for (int i = 0; i <= n; ++i) {
        if (a[i] == target) answer = i;
    }
    return answer;
}

