Consider this implementation of strtok() in C
char *pt;
pt = strtok(line, ":");
if (pt != NULL)
{
pt = strtok(NULL, ":");
}
why doesn't pt have to be explicitly allocated memory? Like pt[128] or pt = malloc(...)? I would have thought the above implementation would segfault. Do I have to worry about deallocation?
linehas to reference modifiablechararray and moststrtokimplementations are using this memory.It is the reason why you do not have to provide any additional memory for this operation.
Remember that
linewill be modified (destroyed) during this operation.ptwill hold (if notNULL) the reference to one of the elements of the array referenced byline