+ 6
The return value isn't used by the program itself, but by the operating system. Depending on your operating system, you can see the return value with a statement like "echo $?" (Linux) immediately after you run the program in a console. A return value other than 0 won't stop your program from running properly, but it will signal to the OS that something went wrong.
+ 1
Anna But what would the OS do with that?
Like, say I create a program and use return 1; or a value other than 0. It should run fine, but it'll signal that something went wrong, like you said. Now what does the OS do?
+ 1
Daniel Cooper The OS will likely do nothing (it may store the fail in a log file). If the program is part of the system itself then the OS might be programmedâ to know what it means at act accordingly, but not sure how common this would be. Where it can be useful is if you have a program that calls a second program, the first program has access to the return value of the second program.