1. Summary
  2. Files
  3. Support
  4. Report Spam
  5. Create account
  6. Log in

Implicit main

From cpwiki

Jump to: navigation, search

In C, functions are not required to have a return type. These functions are known to have an "implicit return type." This default return type defaults to int.

This, in turn makes it possible to define the main entry function simple as:


However, many programmers (especially those of us at cboard) find this a bad thing. This type of declarations are also deprecated in C89 standard and in fact not supported in C99 and C++, which also makes it a bad idea. It is also a good programming practice that all functions should have an explicit return type, so in effect, main should really be:

int main()

There is also another version of main:

int main(int argc, char* argv[])

Or, another variant that can be used:

int main(int argc, char** argv)

Which can and should be used if the command line arguments passed to the application wants to be accessed and used.

Personal tools