#include
#include
using namespace std;
bool compare(int a, int b)
{
cout << "compare " << a << " and " << b << endl;
return a >= b;
}
int main()
{
int coins[] = {1, 2, 5, 10, 20, 50, 100, 200, 500, 2000};
int n = sizeof(coins) / sizeof(int);
int money = 160;
int lb = lower_bound(coins, coins + n, money, compare) - coins;
cout << lb;
return 0;
}
As by default the lower_bound function returns the address of element >= key. Than why the above code is returning 0 as the index?