Exit Codes

We’ve already seen return values in the context of functions, and by now it’s hopefully apparent that the main purpose of a return value is to communicate a value back to the calling function so that it may use it in some meaningful way. But why, then, does main() sometimes return 0; or return 1;? If main() is the function that drives our entire program… to what is it returning? In this very short section, we won’t dabble too much in where main()’s return values (which are occasionally referred as exit codes, as when main() returns the program necessarily ends) go, but we will touch on why and how we might use them as programmers.