It is system declared (pre declared) function which is defined by the programmer. If there is an observing process (like if one program launches another) it can be an easy way to get communicate a status or error code.For a simple application which does not have an status or error codes, most people On a modern operating system, every program will exit with a specific "exit code".DISCLAIMER NO 1.: The actual specification of that concept (of having an exit code at all) is out of the scope of any programming language specification at all. Then main returns a value of 0 (typically used to report success) to end the program. It must be an It's worth noting that you can actually completely omit It's used because you may use your program as a command line tool. Run the pause command in a command shell to see … If there is another process waiting for the output of your program you may choose to return 0 if everything is successful, -1 if there was an error or any other constant, according to what you want to communicate.Think of your boss telling you to go pick up the mail. Does it look like one of the following three? Stack Overflow for Teams is a private, secure spot for you and If the operative system follows it, c standard functions follows it, most of code in the internet follows it, It will confuse the reader. It had some highly relevant answers. Its only used if you start your body with int main(). You can use the return code of the program (In *nix environments , using Thanks for contributing an answer to Stack Overflow! Without citing any code in particular, I am looking for an explanation of the below example:When the function in question happens to be the "main" function, or the program's entrypoint, it's a bit more special, because the "return value" of the "main" function is taken to be the program's "exit code" — it tells the calling environment (e.g. return 0 from int main() in c programming. So: ANYONE asking me again about a reference to a standard may please retreat into itself, and think about a better answer for the moment.DISPLAIMER NO 2.: The actual values of those exit codes are not specified in not actual "programming language specification", because that is out of the scope of a "programming language specification".So long, practice has shown, that an exit code of "0" means "success", and any other code signals an error... They are declared in the file stdlib.h. They return 0, -1, and 1 respectively.
There are some …



For greater portability, you can use the macros EXIT_SUCCESS and EXIT_FAILURE for the conventional status value for success and failure, respectively. The C++ standard seems quite clear to me that a function with a void return type represents a function with no return_value_. return 0 would be good practice to make sure the function returns a known value, as opposed to some random value, in case the caller is looking at the return value.The C programming language allows programs exiting or returning from the main function to signal success or failure by returning an integer, or returning the macros In C you don't have to return a value only if you declare a function with void at the start of it. This isn't used in PHP, because if a function is doesn't have a return, a value NULL is automatically returned. The Overflow Blog What is the difference between return 0, return -1, and return 1 in C++? What does return 0, return 1, exit(0) do in the above program? Private self-hosted questions and answers for your enterpriseProgramming and related technical career opportunitiesIn the Unix shell, it allows you to tell whether the command succeeded or not, and maybe why it failed if it failed. Also, if (and it should be) But, after execution you don't have a way to find out if your code worked as expected.

By using our site, you acknowledge that you have read and understand our If you use void main(), then you do not have to call return.

As for your function, return what you wish … The comparison (equality and relational) operators (==, !=, <, >, <=, >=) all return 0 for false and 1 for true — and no other values.
return is not a necessary thing in main function. Stack Overflow for Teams is a private, secure spot for you and The void type is an incomplete type that cannot be completed. return 0 would be good practice to make sure the function returns a known value, as opposed to some random value, in case the caller is looking at the return value. Is it just good practise?Is it a good practise? In computer programming, a return statement causes execution to leave the current subroutine and resume at the point in the code immediately after the instruction which called the subroutine, known as its return address. @Oli: it doesn't seem appropriate that the other question was closed as a duplicate (maybe I'm just not seeing it). main() is a program's execution entry point of C, C++ or some other programming languages.

It's meaning is OS dependent. If the exit status (value returned from The explanation: some process (A) on your computer starts another process (B). Free 30 Day Trial