When a segmentation fault occurs, the printf() before it does not execute.
main()
{
printf( "something" );
statement; //this statement causes a segmentation fault
}
In the situation above, why does the printf() not execute?
So do I need to use valgrind in such a case(which prints all printf() before the faulty statement).
Make sure you include a newline "\n"
in your printf statement. Normally, at least in UNIX systems, stdout
is line-buffered so newline character makes the line to appear immediately. You probably omitted "\n"
(or your output is not flushed for other reason) and that's why you can't see the printed string.
Another option is to flush the output yourself using fflush(stdout)
after calling printf
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With