return 0;

3 replies [Last post]
dgoree
Title: NooBot
Joined: 02/13/2012
Posts:
BotPoints: 130
User offline. Last seen 6 years 31 weeks ago.

This isn't urgent, but I was curious about something, and I figured that someone on this site would have a good answer for me.

Why exactly do we end C programs with return 0;? I know that the main method has a return type int, so it needs to return some sort of int at the end of it, but why is it 0? Also, why does our main method have a return type in the first place? What is calling it?

-Daniel Goree
Former...
Senior Project Manager
President
Norman Advanced Robotics (13-0113)

Beta
Beta's picture
Title: The Magnificent
Joined: 02/24/2012
Posts:
BotPoints: 266
User offline. Last seen 9 years 16 weeks ago.

In UNIX, programs return an exit code to denote success or failure. "0" is the exit code for success. You could return "1" if you needed to signal to a calling process that your program did not terminate normally. For Botball and Link programming in general, this value is not too important.

Braden McDorman

Developer of the KIPR Link, KISS IDE, KIPR's 2D Simulator, and CBCJVM.

Reach me at bmcdorman(cat)kipr(dog)org where (cat)=@ and (dog)=. if you need assistance of any kind.

dgoree
Title: NooBot
Joined: 02/13/2012
Posts:
BotPoints: 130
User offline. Last seen 6 years 31 weeks ago.

Ah okay thanks. That makes sense.

-Daniel Goree
Former...
Senior Project Manager
President
Norman Advanced Robotics (13-0113)

ruler501
ruler501's picture
Title: NooBot
Joined: 01/29/2012
Posts:
BotPoints: 367
User offline. Last seen 8 years 4 weeks ago.

The only time I've ever seen these used is in scripting. They are just there to check if the application broke down or something.