为什么我们不使用(无效)主? [英] Why don't we use (void) in main?

查看:81
本文介绍了为什么我们不使用(无效)主?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

人们使用无效的主要()/ *空括号()* /

我已经学会写无效的主要(无效)

任何想法有什么区别?

推荐答案

我不知道是什么标准的今天,但在传统的ANSI C,使用空括号idicates该函数可以接受的任何参数的数目。声明一个无效,从另一方面参数指示功能的只需要零点arguemnts 的。在此情况下(以及其他许多),它确实没有太大的关系。

I'm not sure what the standards are nowadays, but in traditional ANSI C, using empty braces idicates that the function can take any number of arguments. Declaring a void parameter on the other hand indicates that the function only takes zero arguemnts. In this case (and many others), it really doesn't matter too much.

如果你想成为严格的,虽然,它可能是最好的定义无效参数。当然,函数也可以被定义为 INT主(INT ARGC,为const char * argv的[]) - 这,如果你不关心的参数是完全有效的,但常常是不必要的。

If you want to be strict though, it's probably best to define the void parameter. Of course, the main function can also be defined as int main(int argc, const char* argv[]) - which is perfectly valid, but often unnecessary if you don't care about arguments.

这篇关于为什么我们不使用(无效)主?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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