The answer to your question is to swap this:
CountEvenNumbers(numbers[length], length);
for this
CountEvenNumbers(numbers, length);
However, if you continue with coding, a skill you might find invaluable is deciphering warrning/error messages:
"c:2:5: note: expected 'int *' but argument is of type 'int'"
"c:28:1: warning: passing argument 1 of 'CountEvenNumbers' makes pointer from
integer without a cast [enabled by default]"
So what does that mean? It states that on line 28 (CountEvenNumbers( numbers[length] , length );
) it expected you to make a cast of argument 1, meaning you passed it something that it did not expect. So you know something is wrong with the first argument.
The trick here is the other line: expected 'int *' but argument is of type 'int'
It's saying "I wanted a pointer to an integer, but you gave me just an integer". That's how you know you're passing the wrong type.
So what you should be asking yourself is, what type is argument 1? You know if you want to access an element inside the array you need to use the []
's, (you did so on lines 20 and 25 of your code), so by passing numbers[length]
to your function, your trying to pass it a single element1 instead of a full array like it expects.
The other half of this is expected 'int *'
, why would your function expect to get a pointer to an int? Well that's because in C, when you pass an array of (type) it decays to a pointer to (type).
1 of course numbers[length] isn't really an element in your array anyway, it overflows it.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…