VOOZH about

URL: https://www.geeksforgeeks.org/c/functions-that-are-executed-before-and-after-main-in-c/

⇱ Functions that are executed before and after main() in C - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Functions that are executed before and after main() in C

Last Updated : 23 Jul, 2025
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(). Output:
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
Comment
Article Tags: