### Get the Return a Value from an Application

In C and C++, function main can return an integer value. You can use this value to hold the return code from your program.Typically, you return a non-zero value to indicate the program is unable to continue, or a 0 upon normal termination. You can use different values to represent different errors or other conditions.

To make main return a specific value to the operating system, use the return statement or call the exit function and specify the value to be returned. For example, the following program returns the value 6 to the operating system.

>     int main() {
>     // do nothing but set the return code to 6
>        return 6;
>     }

If you do not specify a return value in C, the return code of your program is undefined.

If you do not specify a return value in C++, your program returns a value of zero.

If you launch the program from a batch file, you can check the return code in the batch file with the IFErrorLevel command. For more information on batch files and commands you can use in them, check the help included in your operating system.

On the OS/2 command line, you can get the return code using the SET PROMPT $r command.

IBM C and C++ Compilers provides much more flexible and powerful methods that you can use to deal with exceptional circumstances that can occur during program execution, including signal and exception handling.

Signals and Exceptions
Signal and Exception Handling

Run Your Application

C++ Exception Handling - An Overview
C Structured Exception Handling