The exit() terminates the program much like the return statement in the main function. It return control to the operating system. It closes open files, flushes output buffers, and calls destructors before control is returned to the operating system. The parameter passed to the function are exit status values which communicate to the operating system the program terminated prematurely or everything happened as expected. For example exit(0) (same as return 0) means the program terminated normally. exit(1) (same as return 1) means the program terminated because of some error ( it could not open a file, allocate memory, etc. ).