多少个参数的main()在C / C ++ [英] How many arguments does main() have in C/C++
问题描述
用于什么号的主要参数
?什么变种主
定义是可能的吗?
What numbers of arguments are used for main
? What variants of main
definition is possible?
推荐答案
C ++标准:(<一href=\"http://stackoverflow.com/questions/1621574/mains-signature-in-c/1621664#1621664\">Source)
C++ Standard: (Source)
在C ++ 98标准说在第3.6.1.2
The C++98 standard says in section 3.6.1.2
这应该是一个类型的返回类型
诠释,但除此之外,其类型为
实现定义。所有
实现应允许两个
主要如下定义:INT
main()和INT主(INT ARGC,CHAR *
的argv [])
It shall have a return type of type int, but otherwise its type is implementation-defined. All implementations shall allow both the following definitions of main: int main() and int main(int argc, char* argv[])
通常有3套参数:
- 没有参数/
无效
-
INT ARGC,字符** argv的
-
INT ARGC,字符** argv的,字符** ENV
- no parameters /
void
int argc, char ** argv
int argc, char ** argv, char ** env
其中, ARGC
是命令行数,的argv
是实际的命令行和 ENV
是环境变量。
Where argc
is the number of command lines, argv
are the actual command lines, and env
are the environment variables.
Windows系统:
有关Windows应用程序,你有WinMain函数的入口点具有不同的签名,而不是主要的。
For a windows application you have an entry point of WinMain with a different signature instead of main.
int WINAPI WinMain(
__in HINSTANCE hInstance,
__in HINSTANCE hPrevInstance,
__in LPSTR lpCmdLine,
__in int nCmdShow
);
OS X:(来源)
OS X: (Source)
Mac OS X和达尔文具有包含任意的OS提供的信息,如路径执行二进制第四个参数:
Mac OS X and Darwin have a fourth parameter containing arbitrary OS-supplied information, such as the path to the executing binary:
int main(int argc, char **argv, char **envp, char **apple)
这篇关于多少个参数的main()在C / C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!