Is it possible to call an extra function when main() exits in C?
Thanks!
In a C program, more than one break statement can be executed. In a C program, just one exit function will be executed.
In 'C' you can even call the main() function, which is also known as the "called function" of one program in another program, which is called "calling function"; by including the header file into the calling function.
Calling a Function While creating a C++ function, you give a definition of what the function has to do. To use a function, you will have to call or invoke that function. When a program calls a function, program control is transferred to the called function.
You can register functions to run after main
exits using the atexit
function.
MSDN has a nice succinct example of how this is done. Basically, the functions registered with atexit
are executed in reverse order of when they were registered.
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