void main on-line judge compiler error?

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
pfiesteria
New poster
Posts: 9
Joined: Mon Aug 13, 2007 7:45 am

void main on-line judge compiler error?

Post 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?

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Post 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.

sumankar
A great helper
Posts: 286
Joined: Tue Mar 25, 2003 8:36 am
Location: calcutta
Contact:

Re: void main on-line judge compiler error?

Post 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.

Post Reply

Return to “C++”