Search code examples
cpointerspointer-to-pointer

Where does the pointer "char **strData" point to?


From the code here there is the pointer char **strData = NULL; in line 12. I'm new to C and pointers. I get, that it is a pointer, which points to another pointer. I just don't see the other pointer.

Can somebody help me?


Solution

  • strData = (char**)realloc(strData, sizeof(char**)*(noOfLines+1)); is in the while loop, so strData points to a memory block, which can hold pointer. sizeof(char**) should be sizeof(char*).

    It is followed by strData[noOfLines] = (char*)calloc(MAX_LEN,sizeof(char));, which is the pointer you asked for.

    So strData points to a block of pointers, strData[i] points to a block of chars.