Search code examples
csizeofdouble-pointerpointer-to-pointer

How to get the size of a double pointer array?


How can I get the size of a dynamically allocated array of double pointers? (pointer to pointer datatype)

int tokencnt=1;
tokenv=(char**)malloc(sizeof(char*));

while(tokencnt<11){
 tokenv=(char**)realloc(tokenv,(tokencnt++)*sizeof(char*));
}

printf(*the size of tokenv*);

Solution

  • sizeof does not work with alloc memory. If you malloc stuff you have to keep track of the size. The reason sizeof does not work, is because it will just give you the size of the pointer not the memory it points to.