To count elements matching a condition, initialize a counter to zero and loop through. For each element, check if it satisfies your condition. If yes, increment. After the loop, counter holds the total.
The condition can be anything: counting even numbers, negatives, or values above a threshold. Write if (arr[i] % 2 == 0) count++; for evens. Replace the condition for different tasks.
Counting is a filtering special case. Instead of collecting matches into a new array, you tally how many exist. This uses constant memory regardless of how many matches you find.