title: Is destructor called at the end of main(); strange behavior
body: <pre><code>// Foo.h
  
  class Foo
  {
  
  public:
      Foo();
      ~Foo();
      void exec();
  };
  
  
  // Foo.cpp
  
  Foo::~Foo()
  {
      // Statements A
      exit(0);
  }
  
  //main.cpp
  
  int main()
  {
      Foo foo;
      foo.exec();
  
      // Statements B
      return 0;
  }
  </code></pre>
  
  <p>So why both Statements A and B get executed? And is the destructor called when we reach return 0?</p>
  
  <p>I have seen variants where <code>void exec();</code> is <code>int exec();</code> and the <code>main</code> function ends with<br>
  <code>return foo.exec();</code> does this calls the destructor?</p>
  
  <p>Because I want to have an object that takes control of the code flow from the main function and end the program later.</p>