title: length of char pointer c++
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/492384/how-to-find-the-sizeofa-pointer-pointing-to-an-array">How to find the sizeof(a pointer pointing to an array)</a>  </p>
  </blockquote>
  
  
  
  <p>When declaring a char pointer using malloc for example. is there a way to determine the allocated length. </p>
  
  <p>Example, if I define a char array, I can easily find the number of elements</p>
  
  <pre><code>char a[10];
  a[0]='c';
  cout &lt;&lt; sizeof(a) / sizeof(a[0]);
  </code></pre>
  
  <p>which would yield 10. on the other hand if I tried with a char pointer</p>
  
  <pre><code>char *a;
  a = (char*)malloc(10);
  a[0] = 'c';
  cout &lt;&lt; sizeof(a) / sizeof(a[0]);
  </code></pre>
  
  <p>then it yields 8, which is obviously the size of the pointer, not the allocated length.</p>
  
  <p>is it possible to find the allocated length of a char pointer?</p>
  
  <p>The reason I'm asking this and not use std::string or other, is because I came upon this question while cracking some interview question. so its out of curiousity</p>