There are several possible signatures for main() :
void main() void main(string[] args) void main(char[][] args) void main(wstring[] args) void main(wchar[][] args) void main(dstring[] args) void main(dchar[][] args) int main() int main(string[] args) int main(char[][] args) int main(wstring[] args) int main(wchar[][] args) int main(dstring[] args) int main(dchar[][] args)
If int is the return type, then it is almost the same as in C or C ++. The return value is what the OS / shell sees. If an exception is thrown, a stack trace is printed, and OS / shell sees a nonzero value. I do not know what is this. It may vary depending on the type of exception.
If void is the return type, then OS / shell sees 0. If an exception is thrown, then the stack trace is traced, and the OS sees a non-zero value. Again, I do not know what it is.
In fact, the presence of void main allows you not to worry about returning the value of the OS / shell. Many programs are by no means connected with the return of success or the failure of the OS / shell. Thus, with void, OS / shell always gets 0 if no exception is thrown - which makes sense, since the only program failure at this point is the exception if the exception throws main() . If you care about returning success or failure in OS / shell, you simply use one of the versions that returns an int.
A lot of the signature due to the different types of strings is that you can use almost any of the possible types of strings as input to main() . main() and main(string[] args) are probably the most commonly used.
Jonathan m davis
source share