y not void main() ?

I have heard many times dat void main() is not standard c++ and one should use int main() and return 0.....it makes no difference ..den wats d big deal ??
http://www2.research.att.com/~bs/bs_faq2.html

(Search for "Can I write "void main()"?")
Last edited on
Returning an int is in the spec and thus the main function is declared to return an int.
It does make a difference sometimes, often it won't as the compiler will be able to deal with it being void for compatibility's sake and perhaps issue a warning.
Numbers other than 0 can be returned if you want to, 0 is returned when the program terminates normally, for other situations you might want to use EXIT_FAILURE from cstdlib.
it makes no difference


Your compiler is broken. It should at the very least whinge. Get one that works properly.

It makes a difference. Just because you can't see something doesn't mean it doesn't exist.
Last edited on
@gaminic....tanx
1. It is explicitly forbidden by the C++ language specification
2. It may crash some non-mainstream systems: http://users.aber.ac.uk/auj/voidmain.shtml (mainstream systems had to accomodate for this common error)
It's one more letter to type so the real question is Y WUD U???
@OP if you're developing a command line utility then the return value of main is often used as the return value of the utility. For example if you have a fatal error main should return -1, if successful it should return 0, then if you have some other error cases you want to return out you can return 1,2,3,4,..., 2,147,483,647
Topic archived. No new replies allowed.