What do “segmentation fault” and “bus error” mean?
In general, your program tried to access memory that it shouldn’t have. The cause is likely: uninitialized pointers, inadvertent use of null pointers, mismatched function arguments (especially scanf). Give me an example of a segmentation fault. Here’s the simplest way to generate one. link x = NULL; x->key = 17;. Of course the problem is that you are trying to access the key field of x but it doesn’t exist. A similar thing would happen if you write x->next = y; since the next field of x doesn’t exist either. This seems like a simple thing to avoid, but often occurs when you change the link x, say in a for loop, so that it sometimes points to a real node and sometimes points to NULL. Here’s one way to pinpoint the segmentation fault: replace x->key = 17; with if (x != NULL) x->key = 17; else printf(“Here’s the seg fault!\n”); An easier way is to compile your program with lcc -n. Now, when you run your program, code is automatically inserted to check for following null pointers.