int main() is from the older C times in which you returned a value to the calling program usually the operating system to indicate the success (0) or failure (any other value) of the program.
void main() - well there was no real reason to have the main return a value to the OS so it probably was discarded in later versions in favor of the cleaner void main().
Another reason : void main() is a newer standard, and some compilers require this. It cannot return any value.
int main() is the original standard, and some older compilers require this. It can return a value that can be picked up by the operating system, such as an error message or other feedback.
It comes from the days when programs were run at the console, like DOS, not a GUI like Windows. When the program ended, either correctly or with an error, it would display the return code.
I think modern operating systems do not make any use of this.
Edit:
In the original Kernighan and Ritchie (K&R) C which was the standard for many years, 'void' did not exist.
void main() - well there was no real reason to have the main return a value to the OS so it probably was discarded in later versions in favor of the cleaner void main().
Another reason : void main() is a newer standard, and some compilers require this. It cannot return any value.
int main() is the original standard, and some older compilers require this. It can return a value that can be picked up by the operating system, such as an error message or other feedback.
It comes from the days when programs were run at the console, like DOS, not a GUI like Windows. When the program ended, either correctly or with an error, it would display the return code.
I think modern operating systems do not make any use of this.
Edit:
In the original Kernighan and Ritchie (K&R) C which was the standard for many years, 'void' did not exist.
No comments:
Post a Comment