# bsearch

The FSF.bsearch function allows to perform a binary search of a sorted array.

    void* WINAPI bsearch(
      const void *key,
      const void *base,
      size_t nelem,
      size_t width,
      int (__cdecl *fcmp)(const void *, const void *)
    );

### Parameters

key
Points to a value that you want to search for.
base
Points to an element from which you want the search to be started.
nelem
The number of elements in the array you want to search.
width
The size of each element in bytes.
fcmp
User-defined comparison function that must be declared with __cdecl - C-style calling convention. This function must compare two accepted elements and return an integer value:

*elem1 < *elem2 | - fcmp returns value < 0
*elem1 == *elem2 | - fcmp returns value == 0
*elem1 > *elem2 | - fcmp returns value > 0

### Return value

bsearch returns the address of the first occurrence of key value in the array base or NULL if no occurrence found.

### Remarks

See the C/C++ run-time library reference for more information.

### Example

See also:
FSF.qsort