What is the error in my code?

#include
using namespace std;

int last(int *a , int n,int m)
{
if(n == 0)
return -1;
if(a[n-1] == m)
{
return n;
}
return last(a,n-1,m);
}
int main()
{
int n;
cin>>n;
int a[n];
int m;
cin>>m;
for(int i = 0 ; i< n ; i++)
{
cin>>a[i];
}
cout<<last(a,n,m);
return 0;
}

hello @dhruvtrehan45

here it should be
return n-1 ;
because indexing is 0 based

Still not working ; please check

wait i m checking. . . . . . . . .

read m in last (i.e after reading array elements)

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.