Notices

Overclockers Forums > Software > Programming Tips and Tricks
Programming Tips and Tricks
Forum Jump

Another C++ question...

Post Reply New Thread Subscribe Search this Thread
 
 
Thread Tools
Old 12-30-01, 05:45 PM Thread Starter   #1
Bmxpunk86pl
Member

 
Bmxpunk86pl's Avatar 

Join Date: Sep 2001
Location: CT/Poland

 
Another C++ question...


Ok what is the return 0; thing. I m reading a guide on C++ but i dont understand what it says. THis is what it says "The return instruction makes the main() function to finish and return the code that the instruction is followed by, in this case 0. This it is most usual way to terminate a program that has not found any errors during its execution. As you will see in coming examples, all C++ programs end with a sentence similar to this. " I dont quite understand that so can anyone explain in their own words please?
tHanKs
Bmxpunk86pl is offline   QUOTE Thanks
Old 12-31-01, 01:40 AM   #2
XprincoX
bargain hunter

 
XprincoX's Avatar 

Join Date: Aug 2001
Location: Irvine, CA

 
ok it just basically follow the principle that every function that has a declared type NEEDS return a value of that type. So lets say u declare main like:

int main()

So the function will need a return value, an int in this case when the function returns. So by design, the most common return is return 0. This why alotta ppl just make main a void so there is no return type.

Heres a more indepth discussion: http://www.cplusplus.com/doc/tutorial/tut2-2.html

__________________
"If money is the root of all evil, give me all your evil!!" :D
T-bird 1.4 AYHJA @ 1622 <--- RIP DIED IN UNFORTUNATE ACCIDENT 8/01-1/02 :(
XP2000+ -- Epox 8k7a+ -- vantec Aeroflow -- 512 mb Crucial pc2100 -- SB Audigy mp3+ -- GeForce 2 GTS
120 GB WD S.E. -- 80 gig 7200 Maxtor -- Blk Lite-On 24x10x40x -- Blk 16x Lite-On DVD -- DigitalDoc 5 -- NewQ Equalizer -- Directron D30B/Enermax 431w --WinXP Pro/Win2k

-Member of The Avatar Maker's Guild™ :burn:
E.T. Phone Home?

My HeatWare
Member of the Anti-Unethical Overclockers Movement Are you?

Last edited by XprincoX; 12-31-01 at 01:50 AM.
XprincoX is offline   QUOTE Thanks
Old 12-31-01, 04:11 AM   #3
XWRed1
Senior Member

 
XWRed1's Avatar 

Join Date: Oct 2001

 
When you are programming in a proper way, you'd be ending you're functions with a return line, so the calling function knows what the execution status is, or maybe get a variable returned.

When you return from the main function, you will end the program. This is just proper etiquette, and the OS will read the return value (0) and know that the program executed fine. If you were to return a 1, the OS might do something like launch a crash screen.
XWRed1 is offline   QUOTE Thanks

Post Reply New Thread Subscribe


Overclockers Forums > Software > Programming Tips and Tricks
Programming Tips and Tricks
Forum Jump

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Mobile Skin
All times are GMT -5. The time now is 10:40 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
You can add these icons by updating your profile information to include your Heatware ID, Benching Profile ID or your Folding/SETI profile ID. Edit your profile!
X

Welcome to Overclockers.com

Create your username to jump into the discussion!

New members like you have made this the best community on the Internet since 1998!


(4 digit year)

Why Join Us?

  • Share experience
  • Max out your hardware
  • Best forum members anywhere
  • Customized forum experience

Already a member?