指针看的头都大了,还是有点搞不明白,求大神。在下面的代码中char *a3[5] = {"wer","ad","fgg","rt","bg"};先定义了一个字符串指针,在调用函数sortstring(a3,5);,那a3是值还是地址呀,void sortstring(char *a3[],int len)还有传递char *a3[]又是什么??这怎么理解?
- void sortstring(char *a3[],int len){
- //冒泡排序
- char *temp;//临时存放地址
- for (int i = 0; i < len-1; i++){
- for (int j = 0; j < len - 1 - i; j++){
- //比较字符串大小用函数
- if (strcmp(a3[j], a3[j + 1])>0)
- {
- //实现交换
- temp = a3[j];
- a3[j]=a3[j+1];
- a3[j + 1] = temp;
- }
- }
- }
- }
- int main(int argc, const char *argv[]){
- //输入5个字符串并按字母顺序排列
- char *a3[5] = {"wer","ad","fgg","rt","bg"};
- for (int i = 0; i < 5; i++){
- printf("%s\n", a3[i]);
- }
- printf("\n");
- sortstring(a3,5);
- for (int i = 0; i < 5; i++){
- printf("%s\n",a3[i]);
- }
- return 0;
- }
复制代码 |
|