-4

The main() function is known as a user-defined function in C. But how does it differ from other user-defined functions?

Jonathan Leffler
  • 666,971
  • 126
  • 813
  • 1,185
Hossain Azad
  • 52
  • 1
  • 9

1 Answers1

1

The main() function is just a regular user-defined function — but it has two special properties:

  • In a hosted implementation (the normal type), it is the function called by the start-up code.
  • In C99 and later, if execution falls off the end of main() without an explicit return statement, it is equivalent to return 0;. No other function gets that privileged treatment.

See also What should main() return in C and C++? for some caveats about the second point.

Community
  • 1
  • 1
Jonathan Leffler
  • 666,971
  • 126
  • 813
  • 1,185