1.

Which function is called repeatedly by bsearch() to compare search elements against the elements in the array?(a) mblem()(b) wctomb()(c) compar()(d) labs()I got this question during an interview.I would like to ask this question from General Utilities topic in division C Library of C

Answer»

Right option is (c) compar()

To EXPLAIN: void *bsearch(CONST void *key, const void *base, size_t nitems, size_t size, int (*compar)(const void *, const void *))

The COMPARISON function POINTED to by compar() is called with two arguments that point to the key object to be searched and to an array element, in that order. The function shall return a < 0, = 0, or > 0 if the key object is CONSIDERED, respectively, to be less than, to match, or to be greater than the array element.



Discussion

No Comment Found

Related InterviewSolutions