I was wondering what the value is of writing the main function as:
int main(int argc, char* argv[])
as oppposed to: int main()
I see the first example used quite often in programs and don't really understand the value or the difference. I never see the arguments ever used in the programs either. Can anyone enlighten me on the subject?
Also, is there a reason I might want to use void main() rather than int main()? I see that often as well.
1.) This allows you to handle the command line arguments..., argc is the count of how many arugments there are, and argv is an array of the arguments (as char*s)
2.) void main()? It's not really standard practice...so you shouldn't really do it.
(It is a non-portable compiler kludgeextension that some anti-genious invented in pre-history and which has plagued C programmers ever since.)
The reason it exists is still unclear. The reason it continues to exist is because too many people (including authors of C and C++ books, and some suit-managed compiler writers) just don't know it is the Wrong Thing.
In short, remember that main() is not a normal function! That's right, it is a special, abnormal function. It should only be called by the OS (from your POV) and should always return int. Anything else is non-standard and likely to cause problems with the vast majority of compilers (even if it seems to work just fine with your compiler).