Getting error message in my output when i am running this code but the same code is giving the correct output without any error message in devc++

#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int a[n],output[n];
for(int i=0;i<n;i++)
cin>>a[i];
int max=a[0];
for(int i=1;i<n;i++){
if(a[i]>max)
max=a[i];
}
int freq[max+1];
memset(freq,0,sizeof(freq));
for(int i=0;i<=max;++i)
freq[a[i]]+=1;
for(int i=0;i<=max;++i){
for(int j=1;j<=freq[i];++j)
cout<<i<<" ";
}
}

Hi!


Please check the comments in the above code
Thanks!

1 Like

Hey!
Please mark the doubt as resolved if you’re satisfied with the explanation. Also don’t forget to rate your experience as well.
Thanks!

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.