Quote:
Originally Posted by HelloWorld Would the compiler return some kind of an exception if we don't put int return value in the main method? Well, I personally interested in C# more than C++ though for ASP.NET, but I'm just wondering at least to add up for my knowledge |
A compliant compiler will either display an error and refuse to compile the program or compile the program after issuing a warning about the practice.
As somebody already mentioned, returning an integer rather than nothing at all is better because then you can determine whether the program exited due to errors. In fact, on many Linux machines, you can print out a special variable to determine the exit success:
g++ -std=c++98 -o myprog myprog.cpp && myprog
# the program output is here
echo $?
# if $? shows 0, then myprog exited fine (it exited with 0 errors)
As a side note, this is contrary to many other programming implementations, such as the Windows API, where if you return 0 from a function, that means that the function did not exit successfully (did you exit successfully? 0/FALSE).