static int n
is a variable that exist for the entire life of the program and is incremented / decremented upon the creation / destruction of CDummy.
As a consequence it tells the number of existing CDummy.
The main creates one, then 5 all together, then another on the heap, prints the number, destroy one (the one on the heap), prints again the number (one less as before) and - on return - destroy all the others.
A good variant can be this one:
#include <iostream>
using namespace std;
class CDummy
{
public:
static int n;
CDummy() { n++; };
~CDummy() { n--; };
};
int CDummy::n=0;
int main ()
{
cout << Dummy::n << endl; {
CDummy a;
{
cout << Dummy::n << endl; CDummy b[5];
CDummy * c = new CDummy;
cout << Dummy::n << endl; }
cout << a.n << endl; delete c;
}
cout << CDummy::n << endl; return 0;
}