Two other examples to add to Salem's answer... Let's say I want to make a function which closes a file, using a stream, and want to nullify this "ponter" after closing:
Code:
void closefile( FILE **fptr )
{
if ( *fptr ) fclose( *fptr );
*fptr = NULL;
}
The other is where you want an array of strings. A string, in C, is an array of chars where a pointer points to the first char, Like this:
Code:
char *str = "fred";
Here "fred" (and the final NUL char) is allocated somewhere in memory and the address to the first element is assigned to str. But what if you want an array of strings?
Code:
char *strs[] = { "fred", "was", "here", NULL };
strs points to the first pointer, which points to "fred"... We can use a pointer to a pointer of char to iterate through this array:
Code:
char **p = strs;
while ( *p )
puts( *p++ );
[]s
Fred