Q5. stl lower_bound
What will be the output of the following C++ code?
#include
#include
using namespace std;
int main()
{
int arr[5] = { 4, 5, 1, 0, 1 };
sort( arr, arr+5 );
cout<< lower_bound( arr, arr+5, 3 ) - arr <<endl;
return 0;
}
Q5. stl lower_bound
What will be the output of the following C++ code?
#include
#include
using namespace std;
int main()
{
int arr[5] = { 4, 5, 1, 0, 1 };
sort( arr, arr+5 );
cout<< lower_bound( arr, arr+5, 3 ) - arr <<endl;
return 0;
}
@goyal431 The lower_bound() method in C++ is used to return an iterator pointing to the first element in the range [first, last) which has a value not less than val. This means that the function returns the index of the next smallest number just greater than that number.
in this case, that number is 4 and the index will be 3 (because array is sorted).