8.2 二級指標 指標數組

來源:互聯網
上載者:User

標籤:style   blog   http   color   ar   for   2014   div   log   

二級指標找出最大的字元 :
  1. char maxchar(char * str, char** max)
  2. {
  3. char da = *str; //先讓最大的執行第一個字元
  4. *max = str;
  5. while (*str)
  6. {
  7. if (*str > da)
  8. {
  9. da = *str;
  10. *max = str;
  11. }
  12. str++;
  13. }
  14. return da;
  15. }
  16. int main()
  17. {
  18. char str[] = "hello liuwxeia";
  19. char * max = NULL;
  20. char ch = maxchar(str, &max);
  21. printf("%p\t%c\n", max, ch);
  22. printf("%p\n", &str);
  23. return 0;
  24. }



指標數組: 數組裡的每個元素都是指標
int *a[5];         //a是一個數組,5個元素都是int *d的指標                       // sizeof(a)     ----------->   20個位元組。 因為a是一個數組,不是一個指標                        //一個指標4個位元組
對字串數組進行排序:
  1. void show_str(char **s, int n)
  2. {
  3. int i;
  4. for (i = 0; i < n; i++)
  5. {
  6. printf("%s\n", s[i]);
  7. }
  8. }
  9. void sort_str(char **s, int n)
  10. {
  11. int i, j, min;
  12. char * temp;
  13. for (i = 0; i < n; i++)
  14. {
  15. min = i;
  16. for (j = i + 1; j<n; j++)
  17. if (strcmp(s[min], s[j]) > 0)
  18. min = j;
  19. temp = s[min];
  20. s[min] = s[i];
  21. s[i] = temp;
  22. }
  23. }
  24. int main()
  25. {
  26. char *s[] = { "hello", "world", "liuwei", "xuanyuan", "nima" };
  27. show_str(s, 5);
  28. sort_str(s, 5);
  29. printf("*****************\n");
  30. show_str(s, 5);
  31. return 0;
  32. }



ps :參數裡二級指標等價於指標數組
 二維數組等價於數組指標


來自為知筆記(Wiz)

8.2 二級指標 指標數組

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.