lower_bound function of C++ returns a pointer to the first array element that is at least equal to x (the third argument passed to the function). Here is the code which I compiled online using an online compiler for C++.
#include <bits/stdc++.h>
using namespace std;
int main()
{
vector<int> v;
v.push_back(1);
v.push_back(2);
v.push_back(1);
v.push_back(2);
cout<<lower_bound(v.begin(),v.end(),2)-v.begin()<<endl;
return 0;
}
Output I expected was 1 but actual result says 3. Can someone please explain why this is so?