![]() |
The bsearch() is a library function in C that is used to perform binary search on a given sorted array. In this article, we will learn how to use search on an array in C. Example Input: bsearch() with an Array in CTo use bsearch() on a given array we need to pass the sorted array, key (the element we want to search), size of each element in the array, the total number of elements in an array, and a comparator function which will help the bsearch to find the matching value. The comparator function should return the result as
the Syntax of bsearch() bsearch(key, ptr, num, size, comp); C++ Program to Use bsearch with an ArrayThe below example demonstrates the use of bsearch() with an array. C
Output
Value 15 found! Time Complexity: O(log N)
|
Reffered: https://www.geeksforgeeks.org
C Language |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |