Next Previous Contents

## 3.25 bsearch

> Function

>   Do a binary search in a sorted array.

> Header

>   `stdlib.h`

> Declaration

>   `void* __fastcall__ bsearch (const void* key, const void* base, size_t n, size_t size, int (*cmp) (const void*, const void*));`

> Description

>   `bsearch` searches a sorted array for a member that matches the one pointed to by `key`. `base` is the address of the array, `n` is the number of elements, `size` the size of an element and `cmp` the function used to compare the members against the key. The function returns a pointer to the member found, or `NULL` if there was no match.

> Limits

>   - The contents of the array must be sorted in ascending order according to the compare function given.
>   - If there are multiple members that match the key, the function will return one of the members.
>   - The function is only available as fastcall function, so it may only be used in presence of a prototype.
> Availability

>   ISO 9899

> See also

>   qsort

> Example

>   None.

Next Previous Contents