Use of lowerbund

if lower-bound returns the address of element found then how int lb=lower_bound(…)-coins-1;
returns the index of the element?

@pradhumangupta99 we subtract the base address from the given address, and because arrays are stored in contigous memory locations, this will give the number of elements between the 2 addresses, or in other words the index of our needed value.

int is 4 bytes so difference between two addressees would lead into number of bytes not the no index?

@pradhumangupta99 actually, pointers dont work like that. if its a pointer to int, then it jumps 4 bytes, not 1.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.