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's pretty much the same is in C or C++. The value that you return is what the OS/shell sees. If an exception is thrown, then a stack trace is printed, and the OS/shell sees a non-zero value. I don't know what it is. It may vary by exception type.
If void is the return type, then the OS/shell sees 0. If an exception is thrown, then a stack trace is printed, and the OS sees a non-zero value. Again, I don't know what it is.
Essentially, having void main allows you to not worry about returning a value to the OS/shell. Many programs are not in the least bit concerned with returning success or failure to the OS/shell. So, with void, the OS/shell always gets 0 unless an exception is thrown - which makes sense, since the only program failure at that point is if an exception escapes main()
. If you do care about returning success or failure to the OS/shell, then you simply use one of the versions that returns int.
The plethora of signatures due to different string types is that you can use pretty much any of the possible string types as the input to main()
. main()
and main(string[] args)
are probably the most commonly used though.