exit in cpp

In a program if we call exit(0), it exits the program and before that it closes all opened stream.

In C++, it even does destroys the created objects. Is there any function available, which if called will do some basic clean ups (which includes object destruction) ???

Sounds like you are looking for the atexit() function.

yes....but atexit() does not take any arguments. How can this be implemented in object oriented paradigm ???

atexit() does take arguments as it calls a function when exiting the program, however the called function cannot return arguments. Have a look at this page.

If you want your program to return a value, you could try the _exit() function. More info here.

What you want to do is throw an exception.

// Special exception to throw
class exit_exception : public runtime_error
{
  public:
     exit_exception() : runtime_error("Termination"), _code(0) {}
     exit_exception(int code) : runtime_error("Termination"), _code(code){}
     virtual ~exit_exception(){}
     int getStatusCode()const{ return _code; }
  private:
      int _code;
};
// Main function
int main(int argc, char* argv[])
{
    int retcode = 0;
    try {
          // program content...
    }catch(const exit_exception& quit){
         retcode = quit.getStatusCode();
    }
    return retcode;
}
// ...
throw(exit_exception(0)); // Instead of exit(0)
// ...