Javatpoint Logo
Javatpoint Logo

C++ Algorithm Function count()

C++ Algorithm count()function accepts 'val' as argument and compares for the occurrence of element 'val' in the range. The number of occurrence of that element is returned.



first: 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 value

The function returns the number of occurrence of the element 'val' in the range [first,last).

Example 1


50 appear 3 times.
70 appear 2 times.

Example 2


The number of times 6 appear is: 4


The complexity of the function is linear up to a distance between first and last element.

Data races

Some or all of the elements of the range are accessed


The function throws an exception if any of the argument throws one.

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA