You can index a pointer in the same way that you can index an array if all addresses are configured correctly.
Assuming the following declaration:
char **ptr;
Here are the types of different expressions:
Expression Type Equivalent expressions (yield same value)
---------- ---- ------------------------------------ -----
ptr char ** &ptr[0]
*ptr char * ptr[0]
*(ptr+i) char * ptr[i]; &ptr[i][0]
**ptr char ptr[0][0]
*(*(ptr+i)) char ptr[i][0]; *ptr[i]
*(*(ptr+i)+j) char ptr[i][j]
:
ptr , (2- char)ptr[i] i-ptr[i][j] - j- i-ptr++ ++ptr ptr,(*ptr)++ ++(*ptr) *ptr,
, , malloc.
char **ptr = {"foo", "bar", "bletch"};
char **ptr;
ptr[0] = "foo";
ptr[1] = "bar";
ptr[2] = "bletch";
, , , malloc - :
char **ptr = malloc(sizeof *ptr * N);
if (ptr)
{
ptr[0] = "foo";
ptr[1] = "bar";
ptr[2] = "bletch";
...
}
char **ptr = malloc(sizeof *ptr * N);
if (ptr)
{
size_t i;
for (i = 0; i < N; i++)
{
ptr[i] = malloc(sizeof *ptr[i] * M);
if (ptr[i])
{
}
}
}