title: Using exit and a global object
body: <p>I have the following program where i am calling exit() in the destructor. When i create an object of type sample inside main() destructor is called once and program exits normally. But when i create a global object of type sample, "Destructing.." gets printed infinitely. Can anyone please explain how?</p>
  
  <pre><code>#include "iostream"
  #include "conio.h"
  
  using namespace std;
  
  class sample
  {
        public:
       ~sample() {
                      cout &lt;&lt;"Destructing.."&lt;&lt;endl;
                      exit(0);
                  }
  };
  
  sample obj;
  
  int main()
  {
   getch();   
  }
  </code></pre>