How many arguments does main () have in C / C ++

What numbers of arguments are used for main ? What are the possible definitions of main ?

+7
c ++ c main
source share
1 answer

C ++ Standard: ( Source )

The C ++ 98 standard reads in section 3.6.1.2

It must have a return type of int, but otherwise its implementation type. All implementations must have the following main definitions: int main () and int main (int argc, char * ARGV [])

Usually there are 3 sets of parameters:

  • no options / void
  • int argc, char ** argv
  • int argc, char ** argv, char ** env

Where argc is the number of commands, argv is the actual command line, and env is the environment variable.

Window:

For a Windows application, you have a WinMain entry point with a different signature instead of the main one.

 int WINAPI WinMain( __in HINSTANCE hInstance, __in HINSTANCE hPrevInstance, __in LPSTR lpCmdLine, __in int nCmdShow ); 

OS X: ( Source )

Mac OS X and Darwin have a fourth parameter containing arbitrary information provided by the OS, such as the path to the binary executable:

 int main(int argc, char **argv, char **envp, char **apple) 
+22
source share

All Articles