Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Whats wrong with code that uses void main()?

code main uses void wrong
0
Posted

Whats wrong with code that uses void main()?

0

The following code is not usually considered correct: // A: main should not return a void void main() { /* …Whatever… */ } // AA: This is just the same as A: void main(void) { /* …Whatever… */ } The problem is that this code declares main to return a void and that’s just no good for a strictly conforming program. Neither is this: // B: implicit int not allowed in C++ or C99 main() { /* …Whatever… */ } The problem with code example B is that it’s declaring main to return nothing. But not declaring a function’s return value is an error in C++, whether the function is main or not. In C99, the October 1999 revision to Standard C, not declaring a function’s return value is also an error (in the previous version of Standard C an implicit int was assumed as the return value if a function was declared/defined without a return value). But the usual requirement of both Standard C++ and Standard C is that main should be declared to return an int. In other words, this is an acceptable

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123