Syntax of bsearch() in C

void* bsearch(key, base, num, size, compare);

bsearch() Function in C

In C programming language, bsearch() function is used to perform a binary search on a sorted array to search for an element. The name bsearch stands for “binary search” which is an efficient algorithm for finding an item from a sorted list of items. It is defined inside the stdlib.h header file.

Similar Reads

Syntax of bsearch() in C

void* bsearch(key, base, num, size, compare);...

Parameters of bsearch()

The bsearch() function takes five parameters:...

Return Value of bsearch()

The bsearch() function returns two values:...

bsearch() Comparator Function

The comparator function is passed as a parameter to the bsearch() function and it contains the logic to find the matching element....

Example of bsearch() in C

The below example demonstrates how we can search an element using bsearch() in C....