How to debug segmentation fault? What are the best practices to avoid segmentation faults in the code?