8.2 list pointer Array

Source: Internet
Author: User
The second-level pointer identifies the largest character:
 
 
  1. #include <stdio.h>
  2. char maxchar(char * str, char** max)
  3. {
  4. Char da = * STR; // first run the maximum first character
  5. *max = str;
  6. while (*str)
  7. {
  8. if (*str > da)
  9. {
  10. da = *str;
  11. *max = str;
  12. }
  13. str++;
  14. }
  15. return da;
  16. }
  17. int main()
  18. {
  19. char str[] = "hello liuwxeia";
  20. char * max = NULL;
  21. char ch = maxchar(str, &max);
  22. printf("%p\t%c\n", max, ch);
  23. printf("%p\n", &str);
  24. return 0;
  25. }



Pointer array: each element in the array is a pointer.
Int * A [5]; // A is an array. The five elements are pointer to int * D // sizeof (a) -----------> 20 bytes. Because a is an array, not a pointer // a pointer contains 4 bytes
Sort string Arrays:
 
 
  1. #include <stdio.h>
  2. void show_str(char **s, int n)
  3. {
  4. int i;
  5. for (i = 0; i < n; i++)
  6. {
  7. printf("%s\n", s[i]);
  8. }
  9. }
  10. void sort_str(char **s, int n)
  11. {
  12. int i, j, min;
  13. char * temp;
  14. for (i = 0; i < n; i++)
  15. {
  16. min = i;
  17. for (j = i + 1; j<n; j++)
  18. if (strcmp(s[min], s[j]) > 0)
  19. min = j;
  20. temp = s[min];
  21. s[min] = s[i];
  22. s[i] = temp;
  23. }
  24. }
  25. int main()
  26. {
  27. char *s[] = { "hello", "world", "liuwei", "xuanyuan", "nima" };
  28. show_str(s, 5);
  29. sort_str(s, 5);
  30. printf("*****************\n");
  31. show_str(s, 5);
  32. return 0;
  33. }




PS: the second-level pointer in the parameter is equivalent to the pointer array.
Two-dimensional arrays are equivalent to array pointers.


From Weizhi note (wiz)

8.2 list pointer Array

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.