Q:

Why sizeof Variablename / sizeof * VariableName not work as desired?

 class Simple {
      string *data ;
      //some functions and declaration of some variable,const, dest
 };

When I did ;
 data = new string [10] ;

 cout << sizeof data / sizeof *data << endl ;

 ==> 1 // output 

 data = new string [50];
 cout <<sizeof data / sizeof *data <<endl ;

==> 1 // output 

**Why** do all output display the same ?

A:

Because it simply doesn't work at all.
It only works for plain old arrays that are declared this way :
 string a[10];

and it is the only case when this work.
in your case, you can't retrieve the size from the pointers you have. you have to either store the size of what you have, or just use the STL containers which all have a .size() member. The latter is preferable.

A:

Because sizeof is a compile-time calculation, not a run-time one. And your array size is not known until run-time.
sizeof does not know anything about where the pointer points to, so it doesn't matter how big of a buffer you allocated, or even that you allocated a buffer at all. You can even do:
data = NULL;
x = sizeof(*data);

Because it's calculated at compile-time, there is no null-pointer dereferencing.
sizeof only looks at the datatype you pass in, not the data itself. In this case, string*, which is the same size no matter where it points to.
You have a few options to make this "work":

Use a statically-sized array (e.g. string data[50];) where you can use your sizeof idiom, but of course you get all the standard limitations of static arrays then.
Continue to dynamically allocate using new, but just store the array size and pass it around wherever you need it.
Preferred: Use std::vector for arrays -- this is basically the best of all worlds.

