Getting segmentation fault. Please check.
Counting Sort Question
Segmentation fault is occuring because you code is try to access an array index which is out of bounds. You have created an array of size n but actually it should be size equal to the maximum element in the array.
Change line 12 to int arr[1000001]; and then check.
1 Like
Can you please elaborate? Since the user is giving in the size as n, why is this posing as a problem?
Never mind got it
there was an extra = sign in the second last loop.
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.