Sir I can’t understand why am getting a Segmentation fault
Segmentation fault
@debojyoti.koley.dk this approach will not work.
- Make an array of type
pair<string, int>
- Take inputs for name and salary and store it in the above array
- 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
- size of arr array should be big enough for the range you are iterating
- 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.