Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,452 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,129 people online right now. Registration is fast and FREE... Join Now!




void main () or int main () ?

 
Reply to this topicStart new topic

void main () or int main () ?

Armanian
23 Jan, 2008 - 08:52 AM
Post #1

New D.I.C Head
*

Joined: 8 Sep, 2007
Posts: 20


My Contributions
I've always wondered about this and i asked a friend of mine about it however he didnt really answer it, he just changed subject haha tongue.gif

Well i'm still currently doing tutorials in C++ and i've come across many programs code on the net, and some would contain the int main () and some would contain the void main ()

which is better to use and whats the difference - int main () or void main ()


You'll have to pardon my stupid question but i really wanna know biggrin.gif biggrin.gif

User is offlineProfile CardPM
+Quote Post

dontKnowJava
RE: Void Main () Or Int Main () ?
23 Jan, 2008 - 09:15 AM
Post #2

D.I.C Head
**

Joined: 29 Sep, 2007
Posts: 213


My Contributions
void main doesnt return anything and int main returns an int
User is offlineProfile CardPM
+Quote Post

PennyBoki
RE: Void Main () Or Int Main () ?
23 Jan, 2008 - 09:16 AM
Post #3

system("revolution");
Group Icon

Joined: 11 Dec, 2006
Posts: 2,010



Thanked: 7 times
Dream Kudos: 500
Expert In: Java,C++,C

My Contributions
It is better to use int main() because it is standards-complaint, in some compilers if you use void main() you may receive an error.
User is offlineProfile CardPM
+Quote Post

Armanian
RE: Void Main () Or Int Main () ?
23 Jan, 2008 - 09:37 AM
Post #4

New D.I.C Head
*

Joined: 8 Sep, 2007
Posts: 20


My Contributions
ahh thanks ^^
User is offlineProfile CardPM
+Quote Post

Bench
RE: Void Main () Or Int Main () ?
23 Jan, 2008 - 10:43 AM
Post #5

D.I.C Addict
Group Icon

Joined: 20 Aug, 2007
Posts: 683



Thanked: 24 times
Dream Kudos: 150
Expert In: C/C++

My Contributions
Always int main().

Some people may tell you that its "OK" to use void, because some compilers accept it. although many compilers do not accept it (and will either refuse to compile altogether, or throw out a warning). In some cases, the compiler will accept it, but your program may crash while its trying to exit, if the O/S, or some other program needs to be fed a return value from your program.
In some cases, everything will work fine, but you shouldn't count on this.

Also - posting code over the internet which uses void main will often get you attention from experienced C/C++ programmers for the wrong reason (They'll likely tell you to change it).
User is online!Profile CardPM
+Quote Post

Martyr2
RE: Void Main () Or Int Main () ?
23 Jan, 2008 - 11:06 AM
Post #6

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,655



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
int main() is your best friend. void main() will kill you! And not just kill you kill you, but kill you with dull things like spoons or really dull butter knives.

Don't be a dweeb, int main is where it is at! smile.gif
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Void Main () Or Int Main () ?
23 Jan, 2008 - 11:17 AM
Post #7

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 7,116



Thanked: 76 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
I use void main when I seriously don't care what the return code from my program to the OS may be... & I also know that I get sh!t for it, & I deserve it, cuz it's not standard code, it's crap code.

Just as long as you understand what int main does & why it works, & when you can actually get away with using void main then I don't see a problem with it.


User is online!Profile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/7/09 01:10PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month