Javatpoint Logo
Javatpoint Logo

C++ Algorithm Function find()

C++ Algorithm find() function specifies a value in the argument list, a search for that value is made in the range, the iterator starts the search from the first element and goes on to the last element, if the element is found in the range then it is returned otherwise the last element of the range is given.

Syntax

Parameter

first: It specifies the first element of the range.

last: It specifies the last element of the range.

value: It specifies the value which is being searched in the range.

Return value

The function returns an iterator to the first element of the range that is equal to the value. If no such element is found, then the function returns the last element.

Example 1

Output:

Elements that are found in newints: 60
Elements that are found in newvector: 60

Example 2

Output:

Intitial vector: 50 60 70 80
The element 30 has been found  at position: 2

Complexity

The function moves in a linear way, starting from the first element going towards the last one. For each element of the list value of 'pred' is checked. The search goes on until a mismatch for the 'pred' value is encountered.

Data races

Either all the objects in the specified range or some of them are accessed by the function.

Exceptions

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






Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA