Upper_bound

Hello,
I'm having a problem using std::upper_bound
here is the code:
1
2
3
4
5
6
7
8
9
# include <iostream>
# include <algorithm>
using namespace std;
int a[]={1,1,3,4};
int main()
{
	int *p2=upper_bound(a,a+4,1);
	cout<<*p2<<endl;
}


It is returning 3, why is that shouldn't it return 2?
upper_bound returns an iterator

dereferencing the iterator gives you the element the iterator refers to. In this case it is the element at position 2, which is 3.

http://ideone.com/UV4eJn
thank you very much.
Topic archived. No new replies allowed.