Take this code for example:
  class MyClass
   {
   public:
  ~MyClass()
   {
     cout << "Destructor called\n";
    }
   };
  int main()
   {
      MyClass Testvar;
      //  destructer called for this
      MyClass *ptrvar;
      ptrvar = &Testvar;
      // but not for this
   }
It brings a lots of confusions to me. The code above prints: Destructor called only once. I declared two MyClass instances inside main, one of them is a normal variable of type MyClass, and other is a pointer of same type pointing to the normal variable. There is no need of destructor here (no dynamic allocations) but I defined one in the class for a sake of example. So, because two class instances are defined, the destructor should be called twice. But that doesn't happened when I run this code. If I remove the pointer and define one more normal instance, the program prints:
Destructor called Destructor called
My observation is that destructors are not implicitly called when a pointer instance goes out of scope. Am I right or just missing something.
 
     
     
    