With GCC family of C compilers, we can mark some functions to execute before and after main(). So some startup code can be executed before main() starts, and some cleanup code can be executed after main() ends. For example, in the following program, myStartupFun() is called before main() and myCleanupFun() is called after main().
startup code before main() hello cleanup code after main()
Like the above feature, GCC has added many other interesting features to standard C language. See this for more details.
Related Article :
Executing main() in C – behind the scene
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Is it fine to write "void main()" or "main()" in C/C++?
- Anything written in sizeof() is never executed in C
- C/C++ program for calling main() in main()
- Difference between "int main()" and "int main(void)" in C/C++?
- Can main() be overloaded in C++?
- What does main() return in C and C++?
- Executing main() in C/C++ - behind the scene
- How to change the output of printf() in main() ?
- How to write a running C code without main()?
- return statement vs exit() in main()
- How to print "GeeksforGeeks" with empty main() in C, C++ and Java?
- Functions in C/C++
- Thread functions in C/C++
- Macros vs Functions
- Nested functions in C
- C | Functions | Question 7
- C | Functions | Question 6
- C | Functions | Question 5
- C | Functions | Question 4
- C | Functions | Question 11