Why run error? in the given problem

#include
using namespace std;
int main() {
long n;
cin>>n;
long a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
long m;cin>>m;
int j;
for(j=0;j<n;j++){
if(m==a[j]){
cout<<j;
break;
}
}
if(j==n){
return -1;
}

return 0;

}

It should be cout<<-1 not return-1
Return -1 means abnormal ending

@rounaqkhandelwal24
I have marked many doubt asked by you as resolved
Kindly check them and give your feedback
If you want to ask something feel free to ask

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.