gcc 4.4.4 c89
Я понимаю, что указатели в порядке. Однако я перехожу к указательным массивам и указателям на указатели.
Я общался с этим фрагментом кода и оставил комментарии к тому, что, как я думаю, понял.
Большое спасибо за любой совет, если мои комментарии верны с линией кода?
void increment_ptr()
{
/* Static char array */
char src[] = "rabbit";
/* pointer to array of pointers to char - create 6 pointers in this array */
char *dest[sizeof(src)];
size_t i = 0;
/* pointer to a char */
char* chr_ptr = NULL;
/* pointer to pointer that points to a char */
char** ptr_ptr = NULL;
/* chr_ptr pointer now points to the memory location where 'rabbit' is stored. */
chr_ptr = src;
/* ptr_ptr points to the first memory address of the pointer array of where dest is stored */
ptr_ptr = dest;
/* Deference chr_ptr and keep going until nul is reached 'rabbit\0' */
while(*chr_ptr != '\0')
/* deference ptr_ptr and assign the address of each letter to the momory location where
ptr_ptr is currently pointing to. */
*ptr_ptr++ = chr_ptr++;
/* reset the ptr_ptr to point to the first memory location 'rabbit' */
ptr_ptr = dest;
/* Keep going until NULL is found - However, my program never finds it, ends in UB */
while(ptr_ptr != NULL) {
/* Dereference what the pointer to pointer is pointing at the memory lcoation */
printf("[ %s ]\n", *ptr_ptr++);
}
}