ポインタのポインタ(ダブルポインタ)
#include <stdio.h>
typedef struct a {
int x;
} a_t;
int main(int argc, char *argv[])
{
a_t **ppA_t;
a_t *pA_t;
a_t at;
pA_t = &at;
/* set double pointer */
ppA_t = &pA_t;
pA_t->x = 100;
printf("%d\n", (*pA_t).x);
printf("%d\n", pA_t->x);
printf("%d\n", (*ppA_t)->x);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main () {
char **buffer;
int i = 0;
buffer = (char **)malloc(sizeof(char*) * 4);
for ( i=0; i<4; i++ ) {
buffer[i] = (char *)malloc(12);
sprintf(buffer[i], "%d", i);
}
for ( i=0; i<4; i++ ) {
printf("%s\n", buffer[i]);
}
for ( i=0; i<4; i++ ) {
free(buffer[i]);
}
free(buffer);
return 0;
}