什么是main()的返回? [英] What does main() return?

查看:152
本文介绍了什么是main()的返回?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  

可能重复:结果
  什么都要用C的main()的返回/ C ++?


什么价值这个函数返回。只是普通的主力。

 的main()
{
...
}

如果函数有两个电源,会发生什么?


解决方案

  

什么价值这个函数返回。


必须声明为返回一个 INT 。返回值被传递给呼叫者,这通常是在操作系统


  

程序启动


  
  

称为在程序启动时的功能被命名为主力。实施没有声明
  原型此功能。它应带有int和返回类型来定义不
  参数:


  INT主要(无效){/ * ... * /}


  

或具有两个参数(此处称为argc和argv,虽然任何名称可能是
  使用,因为它们是局部的,其中声明它们的功能):


  INT主(INT ARGC,CHAR *的argv []){/ * ... * /}



  

如果函数有两个电源,会发生什么?


链接器报告错误。

Possible Duplicate:
What should main() return in C/C++?

What value does this function return. just plain main.

main()
{
...
}

and if a function has two mains , what happens?

解决方案

What value does this function return.

main needs to be declared as returning an int. The return value is passed to the caller, which is usually the operating system.

5.1.2.2.1 Program startup

The function called at program startup is named main. The implementation declares no prototype for this function. It shall be defined with a return type of int and with no parameters:

int main(void) { /* ... */ }

or with two parameters (referred to here as argc and argv, though any names may be used, as they are local to the function in which they are declared):

int main(int argc, char *argv[]) { /* ... */ }


and if a function has two mains , what happens?

Linker reports an error.

这篇关于什么是main()的返回?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆