Bsearch
bsearch is a C standard-library function that performs a binary search on a sorted array using a caller-provided comparison function.
Modern C, Third Edition
bsearch is the C standard-library function that performs a binary search on a sorted array using a comparison function.
- How it is used
- Provides generic binary searching for sorted arrays through a caller-supplied ordering function.
- How deep it goes
- Explains the interface, erased array types, element sizing, and comparator contract without descending into search-loop internals.
- Examples
- Uses unsigned comparison code and contrasts safe relational comparison with overflow-prone integer subtraction.
- What you can do after
- Apply it via the C standard library with correctly sized elements and a consistent comparator.
Modern C
bsearch is a C standard library function that searches a sorted array using a caller-provided comparison function.
- How it is used
- Uses a caller-provided comparator to search sorted arrays without depending on their element type.
- How deep it goes
- Defines the interface and comparator contract, but does not explain the search algorithm’s internal steps.
- Examples
- Uses unsigned comparison code and contrasts it with an overflowing integer subtraction comparator.
- What you can do after
- Apply via the C standard library by supplying correctly sized elements and a consistent comparison function.
Related concepts
- comparison functionuses · A comparison function or strategy compares two values and indicates their relative ordering, and sometimes whether they are equivalent.
- binary searchimplements · Binary search is an algorithm that locates a target or boundary in an ordered collection by repeatedly comparing with a midpoint and halving the remaining search range.
- function pointer typeused by · A function pointer is a value that designates a callable function and can be stored, passed, or invoked indirectly.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

