C language middle of the wrong solution Segmentation fault (core dumped)

  In the C language, any operating instructions are inseparable from the operation of memory, so even when there is no grammar compiler operation, but it is possible in the actual operation of the memory for illegal operations, this segment will generate an error Segmentation fault ( core dumped)! To solve the mistakes we must first find the section of the wrong place.

  How to find mistakes in the program?

Segment error is not grammatical errors, it will not prompt an error at compile time, only until run-time error occurs only section, but mistakes will not be prompted on what line, you can find a segmentation fault location by printf () function, as long as the occurrence segment error, then the program will end soon.

for example:

printf("11111!\n");
xxxx;
printf("22222!\n");
yyyy;
printf("33333!\n");
zzzz;

If the execution result of operation of the above code is obtained:

! 11111
! 22222
Segmentation Fault (Core dumped) -> Description mistakes is the emergence of "yyyy;"

Segment error is usually a pointer to a problem, the best place to find mistakes print out the content of the pointer to see that they are not expected to modify the content of the pointer and then, if the list is to draw the logical view your list have no problem

Paragraph summary of steps to resolve the error:

1. Use the printf () function to find the wrong place segment

2. Paragraph error pointer print appears, open the file list or directory to see the return value is not their expected results

3. Modify the code to recompile the results now

Guess you like

Origin www.cnblogs.com/xdd-sdyp/p/11329281.html