I am trying to check the size of pointer memory allocated through malloc()
. For this I write a program in which I initially allocate memory size of 10. Then insert a for loop and keep increasing memory by using realloc()
. I am checking memory size by using sizeof
.
Here is my code:
int main(int argc, _TCHAR* argv[])
{
char *ptr;
long int size;
int count;
ptr = (char *) malloc(10);
size = sizeof(*ptr);
printf("size of ptr is= %d\n",size);
for(count=11;count<=100;count++)
{
ptr=(char *) realloc(ptr,count);
size = sizeof(*ptr);
printf("size of ptr is= %d\n",size);
}
return 0;
}
But I am getting always '1' as output:
So, please tell me if there is any other way to do this.