Possible Duplicate:
How to find the sizeof(a pointer pointing to an array)
When declaring a char pointer using malloc for example. is there a way to determine the allocated length.
Example, if I define a char array, I can easily find the number of elements
char a[10];
a[0]='c';
cout << sizeof(a) / sizeof(a[0]);
which would yield 10. on the other hand if I tried with a char pointer
char *a;
a = (char*)malloc(10);
a[0] = 'c';
cout << sizeof(a) / sizeof(a[0]);
then it yields 8, which is obviously the size of the pointer, not the allocated length.
is it possible to find the allocated length of a char pointer?
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