二级指针指向指针数组的使用 .
二级指针的作用就是指向指针,存储的就是另一个指针的地址,把握住这个中心思想即可.
例: 将指针数组中的字符串进行排序.
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
char *c1[20] = {"abc" , "abcd" , "a" , "abcdef" ,"abcdefg","abcdefgh"};
char **p = NULL;
int count = 0;
p = c1;
while (*p != NULL)
{
count++;
p++;
}
p=c1;
for (int i = 0; i< count -1; i++)
{
for(int j = i+1; j < count; j++)
{
//此排序交换的是地址.
char * temp;
if (strcmp(*(p + i), *(p + j)) > 0 )
{
temp = *(p + i);
*(p+i) = *(p + j);
*(p+j) = temp;
}
}
}
for (int i = 0; i< count ; i++)
{
printf("%s \n",*(p+i));
}
return 0;
}