I've just started programming and I've come to hear the standard beginner's definition of "the use of the return value in main" a lot, but it does not get to the point I am trying to understand. So, yes a return value 0 for 'int main' for example signifies that the programme running was successful and since main is of int datatype, 0 reflects this.
BUT what is the point of this? Won't the computer already know that the code was successful or not? Surely, we could write a flawed code and then return 0, and by that logic, we (the programmers) are saying this code is correct but the compiler actually executes the programme and if it's wrong/flawed it simply cannot operate on it.
Please use explanations that a beginner could understand.
The return code of your program ain't about crashing, its about a functional kind of failure.
For example, the program grep defines exit/failure code 0 as successfully found and 1 as not found. While value 2 gets used for invalid input.
Within scripting, this can be used for some automated logic without the user needing a user to interpret the results.
As you are a beginner, I would recommend to always return zero as you are focusing on how to learn the language. Looking into how applications can connect to each other via exit codes is adding unneeded distraction/complexity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With