问题
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).
回答1:
ptrdiff_t index = pointer_found - array_name;
来源:https://stackoverflow.com/questions/2711653/c-how-to-convert-a-pointer-in-an-array-to-an-index