Home > Blogs > 30 C++ Tips in 30 Days: Tip # 13 exit() return codes

30 C++ Tips in 30 Days: Tip # 13 exit() return codes

By  Dec 1, 2007

Topics: Programming, C/C++

The std::exit() terminates the curremt program and returns an exit code to the environment. What do the return values of exit() mean?

By default, exit() is called implicitly when main() terminates normally. The return value of such a successful program termination is 0. To indicate an error, the program must call exit() explicitly. By convention, the valid range of values is -128 to 127. Value that are lower than -128 or higher than 127 are truncated on some platforms. Therefore, it's best to stick to this range. By convention, abnormal exit statuses are grouped into two categories: system reserves statuses, which are any of the negative values between -1 and -128, and use-defined error codes which are 1-127.

Become an InformIT Member

Take advantage of special member promotions, everyday discounts, quick access to saved content, and more! Join Today.

Other Things You Might Like

Xamarin Unleashed

Xamarin Unleashed