Home>Article>Backend Development> 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#include #include //注意要包含该头文件 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; }
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!