[Solved] Why use size of character pointer


As already noted in the comments, char *str[10]; depicts an array of char pointers. This would be useful, for example, if the length of strings this object will contain is not known until run-time. Once at run-time, it is determined that the length of string for each char * needs to be 25 (for example), then memory can be dynamically created on the heap:

for(i=0;i<10;i++)
{
    str[i] = calloc(26,1);//room for 25 char plus NULL terminator for each char *
}

If string length is known before run-time, then the array of char arrays can be created on the stack as:

char str[10][26]

Either of these methods work to create arrays of strings. The first method requires that memory be freed when finished using the object:

for(i=0;i<10;i++)
{
    if(str[i]) free(str[i]);
}

solved Why use size of character pointer