Lower and upper _bound

Why my same code is not working in function

#include
#include<bits/stdc++.h>
using namespace std;
int freq(int ar[],int key)
{
int n=sizeof(ar)/sizeof(int);
auto it_l1=lower_bound(ar,ar+n,10);
auto it_u1=upper_bound(ar,ar+n,10);
cout<< it_u1-it_l1<<endl;
return it_u1-it_l1;
}

int main()
{
int ar[]={5,7,8,9,10,10,10,15,89,90};
int n=sizeof(ar)/sizeof(int);
auto it_l=lower_bound(ar,ar+n,10);
auto it_u=upper_bound(ar,ar+n,10);
cout<< it_u-it_l<<endl;
int key=10;
cout<<freq(ar, key);

}

When we pass an array only a pointer to first element is passed, because of that reason the value of n in your freq function is always 1. You need to pass size off array to the function as well.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.