Page 1 of 1

void main on-line judge compiler error?

Posted: Sun Mar 16, 2008 6:30 am
by pfiesteria
why following code on-line judge compiler error?

Code: Select all

void main(){
}
when I using following code, it's ok.

Code: Select all

int main(){
return 0;
}
I want to ask, when I using int main(),
what value should I return?return 0? or other value?
and why I can't use void main instead of int main?

Posted: Sun Mar 16, 2008 12:17 pm
by mf
Current C++ standard requires that you use 'int main()'.

It should return 0. Non-zero exit code is used to indicate runtime errors, which is yet another reason to avoid 'void main()' in C - should it by accident return a non-zero value to caller, your submission will be judged as RE.

Re: void main on-line judge compiler error?

Posted: Fri May 16, 2008 12:58 pm
by sumankar
This has come up so often that this should probably go into a coding styles FAQ (if its not already there).
mf wrote:Current C++ standard requires that you use 'int main()'.
More meat to mf's statement -- void main() *never was* C++; read this.