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