int main(int argc, char *argv[])
{
char *a[10] = {0};
int i, j = 1;
for(i = argc - 1; i > 0; i--)
{
a[j] = (char *)malloc(sizeof(char)); //指针数组中的每个值都是指针,使用时需要为它分配地址
strcpy(a[j], argv[i]);
j++;
}
for(i = 1; i < argc; i++)
{
printf("%s ", a[i]);
}
return 0;
}
强调: 指针数组中的每个值都是指针,使用时需要为它分配
关于指针需不需要使用 malloc 分配内存
指针定义时需要初始化 让其 指向 NULL 然后在使用到时需要使用 malloc