D
david
hi friends, don't understand this:
/*
**p is a pointer to *a[], but if *a stops increasing when reads abc,
where is pointing *p??
*/
#include <stdio.h>
int main(void)
{
char *a[] = {"abc", "def", "ghi", "jkl", NULL};
char **p;
p = (char **)a;
while (*p) {
while (**p) {
printf("*a=%p *p=%p %c %s\n", *a, *p, **p, *p);
(*p)++;
}
p++;
}
return 0;
}
/*
Returns
david@debian:~$ ./demo
*a=0x4005ec *p=0x4005ec a abc
*a=0x4005ed *p=0x4005ed b bc
*a=0x4005ee *p=0x4005ee c c
*a=0x4005ef *p=0x4005f0 d def -----> Here *a stops inc, ¿where is
pointing *p?
*a=0x4005ef *p=0x4005f1 e ef
*a=0x4005ef *p=0x4005f2 f f
*a=0x4005ef *p=0x4005f4 g ghi
*a=0x4005ef *p=0x4005f5 h hi
*a=0x4005ef *p=0x4005f6 i i
*a=0x4005ef *p=0x4005f8 j jkl
*a=0x4005ef *p=0x4005f9 k kl
*a=0x4005ef *p=0x4005fa l l
*/
/*
**p is a pointer to *a[], but if *a stops increasing when reads abc,
where is pointing *p??
*/
#include <stdio.h>
int main(void)
{
char *a[] = {"abc", "def", "ghi", "jkl", NULL};
char **p;
p = (char **)a;
while (*p) {
while (**p) {
printf("*a=%p *p=%p %c %s\n", *a, *p, **p, *p);
(*p)++;
}
p++;
}
return 0;
}
/*
Returns
david@debian:~$ ./demo
*a=0x4005ec *p=0x4005ec a abc
*a=0x4005ed *p=0x4005ed b bc
*a=0x4005ee *p=0x4005ee c c
*a=0x4005ef *p=0x4005f0 d def -----> Here *a stops inc, ¿where is
pointing *p?
*a=0x4005ef *p=0x4005f1 e ef
*a=0x4005ef *p=0x4005f2 f f
*a=0x4005ef *p=0x4005f4 g ghi
*a=0x4005ef *p=0x4005f5 h hi
*a=0x4005ef *p=0x4005f6 i i
*a=0x4005ef *p=0x4005f8 j jkl
*a=0x4005ef *p=0x4005f9 k kl
*a=0x4005ef *p=0x4005fa l l
*/