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.
- Anything written in sizeof() is never executed in C
- Difference between "int main()" and "int main(void)" in C/C++?
- C/C++ program for calling main() in main()
- Is it fine to write "void main()" or "main()" in C/C++?
- How to print "GeeksforGeeks" with empty main() in C, C++ and Java?
- What does main() return in C and C++?
- return statement vs exit() in main()
- How to change the output of printf() in main() ?
- Can main() be overloaded in C++?
- How to write a running C code without main()?
- Executing main() in C/C++ - behind the scene
- What happens when a function is called before its declaration in C?
- Write one line functions for strcat() and strcmp()
- fill() and fill_n() functions in C++ STL
- Forward List in C++ | Set 1 (Introduction and Important Functions)
- strdup() and strndup() functions in C/C++
- atol(), atoll() and atof() functions in C/C++
- asctime() and asctime_s() functions in C with Examples
- isalpha() and isdigit() functions in C with cstring examples.
- Static functions in C