Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
272 views
in Technique[技术] by (71.8m points)

c - Why don't we use (void) in main?

People use void main() /*empty parens ()*/

I have been taught to write void main(void)

Any ideas what the difference is?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...