Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
Visual C++
C/C++ Languages
Basic Concepts

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Visual C++ Language Reference
main: Program Startup

A special function called main is the starting point of execution for all C and C++ programs. If you are writing code that adheres to the Unicode programming model, you can use the wide-character version of main, wmain.

The main function is not predefined by the compiler; rather, it must be supplied in the program text.

The declaration syntax for main is:

int main( );

or, optionally:

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

The declaration syntax for wmain is as follows:

int wmain( );

or, optionally:

int wmain(int argc, wchar_t *argv[], wchar_t *envp[]);

You can also use _tmain, which is defined in TCHAR.h. _tmain will resolve to main unless _UNICODE is defined, in which case _tmain will resolve to wmain.

The types for argc and argv are defined by the language. The names argc, argv, and envp are traditional, but are not required by the compiler. See Argument Definitions for more information and for an example.

Alternately, the main and wmain functions can be declared as returning void (no return value). If you declare main or wmain as returning void, you cannot return an exit code to the parent process or operating system using a return statement; to return an exit code when main or wmain is declared as void, you must use the exit function.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
No space in signatures      Marcelo Lopez Ruiz - MSFT ... Thomas Lee   |   Edit   |   Show History

Looks like spaces are missing in all code snippets.

For example:

intmain();

should be

int main();
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker