Segmentation fault

Sir I can’t understand why am getting a Segmentation fault

@debojyoti.koley.dk this approach will not work.

  1. Make an array of type pair<string, int>
  2. Take inputs for name and salary and store it in the above array
  3. Sort the array

@Ishitagambhir Thank you, ma’am. But can you please tell me why am getting Segmentation fault? Am not getting that. I got it that there is problem in my approach but not able to find the error in code.

@debojyoti.koley.dk segmentation fault comes when you try to access unauthorized memory like an out of bound index. You are taking arr[i] as an index for arrCpy so

  1. size of arr array should be big enough for the range you are iterating
  2. the values of arr[i] should not go out of bounds

If you still have any confusion try to dry run using a pen and paper and see what memory and index is being accessed

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.

@Ishitagambhir thank you ma’am I got it.