C Interview Questions and Answers


I have a program that seems to run correctly

I have a program that seems to run correctly, but it crashes as it's exiting,
after the last statement in main(). What could be causing this?

There are at least three things to look for:

1. If a semicolon in a previous declaration is missing, main might be inadvertently
declared as returning a structure, conflicting with the run-time startup code's

2. If setbuf or setvbuf is called, and if the supplied buffer is an automatic, local
variable of main (or any function), the buffer may not exist any more by the time
the stdio library tries to perform its final cleanup.

3. A cleanup function registered by atexit may have an error. Perhaps it is trying
to reference data local to main or to some other function which no longer exists.

Posted by:Richards