C++ Algorithm Function count_if ()Last Updated : 17 Mar 2025 C++ Algorithm count_if() function has a 'pred' value and returns the count of the elements in the range [first,last) for which the value of pred is true. SyntaxParameterfirst: It is an input iterator to the first element in the range. last: It is an input iterator to the last element in the range. val: It is the element whose occurrence is being searched in the range. Return valueThe function returns the number of element in the range [first,last) for which the value of pred is true. Example 1Output: newvector contains 5 odd values. Example 2Output: Count of even number is: 10 ComplexityThe complexity of the function is linear up to a distance between first and last element. Data racesSome or all of the elements of the range are accessed ExceptionsThe function throws an exception if any of the argument throws one. Next TopicC++ Algorithm equal Function |
We request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India