Last Updated :
10 Apr, 2024
vector <int> vec = {2, 2, 2, 5, 5, 7, 7, 8, 8, 9};
vector<int> :: iterator up;
up = upper_bound(vec.begin(), vec.end(), 6);
cout << (up - vec.begin())<< \" \" << *up;
Predict the output for the above program
(A) 4 6
(B) 5 6
(C) 6 7
(D) 5 7
Answer: (D)
Explanation:
up – vec.begin(): returns an iterator to the first element which has value greater than 6.
*up: returns the first element which has value greater than 6 i.e. 7.
Share your thoughts in the comments
Please Login to comment...