C - how to convert a pointer in an array to an index?

Posted by hatorade on Stack Overflow See other posts from Stack Overflow or by hatorade
Published on 2010-04-26T07:13:48Z Indexed on 2010/04/26 7:23 UTC
Read the original article Hit count: 296

Filed under:
|
|
|

In the many search functions of C (bsearch comes to mind) if a result is found, a pointer to the spot in the array is returned. How can I convert this pointer to the index in the array that was searched (using pointer arithmetic, i assume).

© Stack Overflow or respective owner

Related posts about c

    Related posts about pointer-arithmetic