c语言中 int main()什么意思, c语言中的int main()中的int main 他们各自...

c\u8bed\u8a00\u4e2d\u7684int main()\u662f\u4ec0\u4e48\u610f\u601d?

\u542b\u4e49\u5982\u4e0b\uff1a
\uff081\uff09\u4e00\u4e2aWindows\u5e94\u7528\u7a0b\u5e8f\u7684\u6267\u884c\u8fc7\u7a0b\u662f\uff1a \u64cd\u4f5c\u7cfb\u7edf\u8c03\u7528C/C++\u8fd0\u884c\u671f\u542f\u52a8\u51fd\u6570->\u542f\u52a8\u51fd\u6570\u505a\u5b8c\u6240\u6709\u521d\u59cb\u5316\u5de5\u4f5c\u540e->\u8c03\u7528\u5e94\u7528\u7a0b\u5e8f\u8fdb\u5165\u70b9\u51fd\u6570\uff08\u5373\u6211\u4eec\u7684\u4e3b\u51fd\u6570\uff09 \u3002
\uff082\uff09\u800c\u4e3b\u51fd\u6570\u8fd4\u56de\u65f6->\u542f\u52a8\u51fd\u6570\u4fbf\u8c03\u7528C/C++\u8fd0\u884c\u671f\u7684exit\u51fd\u6570\u3002
\uff083\uff09\u901a\u5e38\u6211\u4eec\u7684\u4e3b\u51fd\u6570\u6709\u8fd9\u6837\u4e00\u4e2a\u6574\u578b\u8fd4\u56de\u503c\uff0c\u5176\u610f\u4e49\u4e3a\uff1a\u5f53\u4e3b\u51fd\u6570\u8fd4\u56de\u65f6\uff0c\u8fd9\u4e2a\u8fd4\u56de\u503c\u5c31\u4f1a\u4f20\u9012\u7ed9\u8fd9\u4e2aexit\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\uff0cexit\u51fd\u6570\u5148\u505a\u5b8c\u6240\u6709\u6e05\u7406\u5de5\u4f5c\uff0c\u7136\u540e\u8c03\u7528\u64cd\u4f5c\u7cfb\u7edf\u7684ExitProcess\u51fd\u6570\u5e76\u5c06\u8fd4\u56de\u503c\u4f20\u9012\u7ed9\u5b83\uff0c\u8fd9\u4f7f\u5f97\u64cd\u4f5c\u7cfb\u7edf\u80fd\u591f\u64a4\u9500\u8fdb\u7a0b\u5e76\u8bbe\u7f6e\u9000\u51fa\u4ee3\u7801\u3002\u901a\u5e380\u8868\u793a\u6b63\u5e38\u8fd4\u56de\uff0c\u975e\u96f6\u7684\u5176\u4ed6\u503c\u8868\u793a\u51fa\u73b0\u9519\u8bef\u3002
\uff084\uff09\u6211\u4eec\u7684\u4e3b\u51fd\u6570\u53ef\u4ee5\u5b9a\u4e49\u4e3a\u7c7b\u4f3cvoid main()\u8fd9\u4e2a\u6837\u5b50\uff0c\u5373\u65e0\u8fd4\u56de\u503c\uff0c\u90a3\u4e48\u8fd9\u4e2a\u65f6\u5019\u5c31\u4e0d\u80fd\u7528return\u8bed\u53e5\u628a\u9000\u51fa\u4ee3\u7801\u4f20\u9012\u7ed9\u7236\u8fdb\u7a0b\u6216\u64cd\u4f5c\u7cfb\u7edf\uff0c\u6b64\u65f6\u64cd\u4f5c\u7cfb\u7edf\u53ef\u4ee5\u64a4\u9500\u8fdb\u7a0b\u4f46\u4e0d\u4f1a\u8bbe\u7f6e\u9000\u51fa\u4ee3\u7801\u3002\u5f53\u7136\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4f60\u8fd8\u662f\u6709\u529e\u6cd5\u8bbe\u7f6e\u9000\u51fa\u4ee3\u7801\uff0c\u90a3\u5c31\u662f\u663e\u5f0f\u5730\u8c03\u7528exit\uff08\u9000\u51fa\u4ee3\u7801\uff09\u3002
\u53ef\u4ee5\u89e3\u91ca\u4e3a\uff1a\u8f93\u51fa\u51fd\u6570\u5728\u4e3b\u51fd\u6570\u91cc\uff0c\u662f\u4ee5\u6d6e\u70b9\u578b\u6570\u636e\u8f93\u51fa\u7684\uff0c\u8fd9\u4e2a\u8fd4\u56de\u503c\u662f\u5728\u5c4f\u5e55\u4e0a\u663e\u793a\u7684\u3002\u800c int main() \u4e3b\u51fd\u6570\u8fd4\u56de\u7684\u503c\u662f0\uff0c\u5373 return 0; \u8fd9\u4e2a\u8fd4\u56de\u503c\u4e0d\u662f\u663e\u793a\u5728\u5c4f\u5e55\u4e0a\u7684\uff0c\u800c\u662f\u51fd\u6570\u7684\u4e00\u90e8\u5206\uff0c\u56e0\u4e3aC\u90fd\u662f\u51fd\u6570\u7ec4\u6210\u7684\uff0c\u5373\u4f7f\u662f\u4e3b\u4f53\uff0c\u5b83\u4e5f\u662f\u4e00\u4e2a\u5b8c\u6574\u7684\u51fd\u6570\u3002

\u89e3\u91ca\u5982\u4e0b\uff1a
1\u3001int main()\u662fC\u8bed\u8a00main\u51fd\u6570\u7684\u4e00\u79cd\u58f0\u660e\u65b9\u5f0f\uff1b
2\u3001int\u8868\u793a\u51fd\u6570\u7684\u8fd4\u56de\u503c\u7c7b\u578b\uff0c\u8868\u793a\u8be5\u4e3b\u51fd\u6570\u7684\u8fd4\u56de\u503c\u662f\u4e00\u4e2aint\u7c7b\u578b\u7684\u503c\uff1b
3\u3001main\u8868\u793a\u4e3b\u51fd\u6570\uff0c\u662fC\u8bed\u8a00\u7ea6\u5b9a\u7684\u7a0b\u5e8f\u6267\u884c\u5165\u53e3\uff0c\u5176\u6807\u51c6\u7684\u5b9a\u4e49\u683c\u5f0f\u4e3aint main(int argc, char *argv[])\uff1b\u5728int main()\u4e2d\uff0c\uff08\uff09\u4e2d\u6ca1\u6709\u6570\u503c\u8868\u793a\u5165\u53c2\u4e3a\u7a7a\uff0c\u7b49\u540c\u4e8eint main\uff08void\uff09;
4\u3001\u4e8b\u4f8b\u4e2dprintf("%f",a);\u8868\u793a\u5c06a\u7684\u503c\u4f5c\u4e3a\u6d6e\u70b9\u7c7b\u578b\u6253\u5370\u51fa\u6765\uff0c\u5728\u5c4f\u5e55\u4e0a\u663e\u793a\uff0c\u800c\u4e3b\u51fd\u6570\u7684\u8fd4\u56de\u7c7b\u578bint\u4f1a\u5c06\u8fd4\u56de\u7684\u503c\u56de\u4f20\u7ed9\u4e3b\u8c03\u8fdb\u7a0b\uff0c\u800c\u4e0d\u662f\u5728\u5c4f\u5e55\u8f93\u51fa\u3002
5\u3001\u56e0\u6b64\uff0cprintf\u7684\u8f93\u51fa\u7c7b\u578b\u8ddf\u4e3b\u51fd\u6570\u7684\u8fd4\u56de\u7c7b\u578b\u6ca1\u6709\u5173\u7cfb\uff0c\u4e92\u4e0d\u5173\u8054\u3002\u4e8b\u4f8b\u4e2d\uff0creturn 0 \u5bf9\u5e94\u624d\u662f\u4e3b\u51fd\u6570\u7684\u8fd4\u56de\u503c\u7c7b\u578b\u3002

\u62d3\u5c55\u8d44\u6599
\u5728C\u8bed\u8a00\u5f53\u4e2d\uff0c\u4e00\u4e2a\u7a0b\u5e8f\uff0c\u65e0\u8bba\u590d\u6742\u6216\u7b80\u5355\uff0c\u603b\u4f53\u4e0a\u90fd\u662f\u4e00\u4e2a\u201c\u51fd\u6570\u201d\uff1b\u8fd9\u4e2a\u51fd\u6570\u5c31\u79f0\u4e3a\u201cmain() \u51fd\u6570\u201d\uff0c\u4e5f\u5c31\u662f\u201c\u4e3b\u51fd\u6570\u201d\u3002\u6bd4\u5982\u6709\u4e2a\u201c\u505a\u83dc\u201d\u7a0b\u5e8f\uff0c\u90a3\u4e48\u201c \u505a\u83dc \u201d\u8fd9\u4e2a\u8fc7\u7a0b\u5c31\u662f\u201c\u4e3b\u51fd\u6570\u201d\u3002\u5728\u4e3b\u51fd\u6570\u4e2d\uff0c\u6839\u636e\u60c5\u51b5\uff0c\u4f60\u53ef\u80fd\u8fd8\u9700\u8981\u8c03\u7528\u201c\u4e70\u83dc\uff0c\u5207\u83dc\uff0c\u7092\u83dc\u201d\u7b49\u5b50\u51fd\u6570\u3002
main\u51fd\u6570\u5728\u7a0b\u5e8f\u4e2d\u5927\u591a\u6570\u662f\u5fc5\u987b\u5b58\u5728\u7684\uff0c\u4f46\u662f\u4f9d\u7136\u6709\u4f8b\u5916\u60c5\u51b5\uff0c\u6bd4\u5982windows\u7f16\u7a0b\u4e2d\u53ef\u4ee5\u7f16\u5199\u4e00\u4e2a\u52a8\u6001\u94fe\u63a5\u5e93\uff08dll\uff09\u6a21\u5757\uff0c\u8fd9\u662f\u5176\u4ed6windows\u7a0b\u5e8f\u53ef\u4ee5\u4f7f\u7528\u7684\u4ee3\u7801\u3002\u7531\u4e8eDLL\u6a21\u5757\u4e0d\u662f\u72ec\u7acb\u7684\u7a0b\u5e8f\uff0c\u56e0\u6b64\u4e0d\u9700\u8981main\u51fd\u6570\u3002\u518d\u6bd4\u5982\uff0c\u7528\u4e8e\u4e13\u4e1a\u73af\u5883\u7684\u7a0b\u5e8f-----\u5982\u673a\u5668\u4eba\u4e2d\u7684\u63a7\u5236\u82af\u7247--\u53ef\u80fd\u4e0d\u9700\u8981main\u51fd\u6570\u3002
\u53c2\u8003\u8d44\u6599\uff1a\u767e\u5ea6\u767e\u79d1\uff1amain\u51fd\u6570

解释如下:

1、int main()是C语言main函数的一种声明方式;

2、int表示函数的返回值类型,表示该主函数的返回值是一个int类型的值;

3、main表示主函数,是C语言约定的程序执行入口,其标准的定义格式为int main(int argc, char *argv[]);在int main()中,()中没有数值表示入参为空,等同于int main(void);

4、事例中printf("%f",a);表示将a的值作为浮点类型打印出来,在屏幕上显示,而主函数的返回类型int会将返回的值回传给主调进程,而不是在屏幕输出。

5、因此,printf的输出类型跟主函数的返回类型没有关系,互不关联。事例中,return 0 对应才是主函数的返回值类型。

拓展资料

在C语言当中,一个程序,无论复杂或简单,总体上都是一个“函数”;这个函数就称为“main() 函数”,也就是“主函数”。比如有个“做菜”程序,那么“ 做菜 ”这个过程就是“主函数”。在主函数中,根据情况,你可能还需要调用“买菜,切菜,炒菜”等子函数。

main函数在程序中大多数是必须存在的,但是依然有例外情况,比如windows编程中可以编写一个动态链接库(dll)模块,这是其他windows程序可以使用的代码。由于DLL模块不是独立的程序,因此不需要main函数。再比如,用于专业环境的程序-----如机器人中的控制芯片--可能不需要main函数。

参考资料:百度百科:main函数



输出函数在主函数里,是以浮点型数据输出的,这个返回值是在屏幕上显示的。而 int main() 主函数返回的值是0,即 return 0; 这个返回值不是显示在屏幕上的,而是函数的一部分,因为C都是函数组成的,即使是主体,它也是一个完整的函数。

返回值是指你的程序返回给操作系统的值:是int main的整型。printf是输出,是给人看的,是浮点型。这样可以理解了吧?

return 后的数才是决定返回类型的 你return的是0;当然是int型的了

printf("%f",a); f%决定了输出的类型。跟return语句无关

扩展阅读:c语言中void main和int main ... 若有说明int a 3 4 0 ... int main 是什么意思 ... c++中int main 报错 ... int main怎么读 ... c++实现sin ... c语言printf输出格式 ... c语言main必须返回int ... int main在c语言中的作用 ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网