Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

What do “segmentation fault” and “bus error” mean?

0
10 Posted

What do “segmentation fault” and “bus error” mean?

0
10

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.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123