Originally Posted by
Annonymous
Recently, I am seeing a lot of people use void main() instead of int main. Is this a good practice? I use int main, isn't that the correct way? Unless, your trying to shut off warnings about main not returning a value. What are the pros/cons? Which is better?
It's not a choice. The correct forms of main are either...
Code:
int main (void)
{
return errorlevel; // usually 0
}
or
Code:
int main (int argc, char *argv[])
{
return errorlevel; //usually 0
}
Although it's apparently not taught in class... the operating system actually does make use of the return value of main() ... It's used in batch files and shell scripts, it's used when one program launches a child program and so on.
If you use void main() and do not return a value, the address reserved for the return value is uninitialized, basicially containing a random number, and can cause wild misbehaviors in cases where a return value is expected.