Home > Backend Development > C#.Net Tutorial > Detailed explanation of the usage of find function in C language

Detailed explanation of the usage of find function in C language

藏色散人
Release: 2020-02-07 11:26:36
Original
12966 people have browsed it

Detailed explanation of the usage of find function in C language

Detailed explanation of the usage of find function in C language

find() function in C language

The find function is used to find the position of a specified element in an array.

For example: There is an array [0, 0, 5, 4, 4];

Question: Where is element 5? The return value of the find function is 2;

find (the starting position of the array name to find the element, the end position of the array name to find the element, the element you want to find)

Directly enter the code:

#include <iostream>
#include <vector>
#include <algorithm>//注意要包含该头文件
using namespace std;
int main()
{
    int nums[] = { 3, 1, 4, 1, 5, 9 };
    int num_to_find = 5;
    int start = 0;
    int end = 5;
    int* result = find( nums + start, nums + end, num_to_find );
    if( result == nums + end ) 
    {
        cout<< "Did not find any number matching " << num_to_find << endl;
    } 
    else
    {
         cout<< "Found a matching number: " << *result << endl;
    }
    return 0;
}
Copy after login

Recommended Study: c language video tutorial

The above is the detailed content of Detailed explanation of the usage of find function in C language. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template