void main() and int main()

hey will anyone tell me when to use void main() and when to use int main() in 1-d array programming.
Use void main() when you want to violate the ISO C++ standard. That's about the only time I can think of... :)

-Albatross
Its never a good idea to use void main, program should return a value to operating system.
closed account (3hM2Nwbp)
Forgive me for reviving and hijacking a dead-looking thread, but I couldn't help but poke further into this. When a program doesn't "return" a value to the operating system, does the OS just look at the EAX (or equivalent) register for a value? I mean, the OS needs *something* to go on.
For int main() if you leave out a return 0; it will explicitly return 0;.

Tested on GCC MinGW compiler, custom build. Proof (commented out a return 0;):
Process returned 0 (0x0)   execution time : 0.939 s
Press any key to continue.
yes int main is the only function that if you omit return will explicitly return 0;
Obviously Java creator feel returning int is redundant isn't it ? In Java it is always public static void main(String[] args) :P

Sometimes I feel the Java creator knows much about C/C++ and based on that experience create a new programming language that aim to side-step certain tricky issues. Whether those decisions are correct or not is debatable but the fact Java is now widely used in multiple industries is testament to it's influence.

Even Google Android development team chooses Java as it's language but during compilation time they translate the Java bytecode into Dalvik bytecode format instead of the Java class format. A shrewd decision I would say. It is much easier to "attract" existing Java developers to their SDK then try to create a new programming language and then ask developers to learn in order to use the SDK :P

So for the forseeable future, I would say Android SDK should be getting more developers than Apple Objective-C developers. It is just a matter of time.

So for the forseeable future, I would say Android SDK should be getting more developers than Apple Objective-C developers. It is just a matter of time.


To play devil's advocate, objective-c is a (rather nice) superset of C, and there are a bazillion C coders in the world.
closed account (z05DSL3A)
A shrewd decision I would say. It is much easier to "attract" existing Java developers to their SDK then try to create a new programming language and then ask developers to learn in order to use the SDK :P

So for the forseeable future, I would say Android SDK should be getting more developers than Apple Objective-C developers.

"try to create a new programming language", "Objective-C", you do realise that Objective-C has been around longer than Java, don't you? And one of the stated infuences of Java is Objective-C?
+ 1 Albatross. Excellent reply :)

sohguanh wrote:
but the fact Java is now widely used in multiple industries is testament to it's influence.

Indeed, but the same could be said about COBOL, and I'd argue that much for the same reasons. Java looks down on the programmer just like COBOL did. It's not a coincidence it's so verbose either.
Er, I kind of got lost when Java was mentioned. What does Java have to do with choosing void main or int main in C and C++? (Java is an entirely different language, with an entirely different requirements specification.)

The void/int main question is in the top twenty, methinks. Read more here:
http://www.cplusplus.com/forum/beginner/5878/

Hope this helps.
Obviously Java creator feel returning int is redundant isn't it ? In Java it is always public static void main(String[] args) :P

Here's something to think about: Does the JRE return anything?
Topic archived. No new replies allowed.