N/APosted on - 09/20/2011
I'm a beginner at coding, I know that int main () is where the program starts but on some websites I found instead of using int main () ( and return 0; before the last bracket), it was void main().
Is there any difference ? And does it affect the compiling speed ?
using namespace std;
void main() //instead of "int main()"
Int main () and void main, what is the difference ?
Aside from the fact that void main() and int main() are different in their returning types, there is a big difference when it comes to comparing the two.
First, according to the standard, only these two syntax are acceptable for use:
int main ( int argc, char *argv )
int main ()
Therefore, it just means that using void main() is somewhat wrong.
Second, C++ does require a return value to indicate failure or success of a program. Using and declaring void main() doesn't mean that the program you are creating is not returning any value. It simply means that you could have a returned value that is not 0. Experiencing this situation may lead to hours of seeking for a bug on your program, thus compiling your program becomes tedious.
In the case of int main(), it uses the return 0 statement. Having a returned value of 0 (zero) means that the program that you have created has been properly terminated.
Hopefully, this answer helps you.