• 12深入理解C指针之---指针多层间接引用


      该系列文章源于《深入理解C指针》的阅读与理解,由于本人的见识和知识的欠缺可能有误,还望大家批评指教。

      一、指针多层引用

        1、定义:指针可以用不同的间接引用层级,通常使用多重指针或字符数组来实现

        2、特征:

          1)、使用二重字符指针表示

          2)、使用字符数组表示

          3)、使用多重字符指针表示

        3、应用:

          1)、主函数中char **argc参数用法

          2)、主函数中char *argc[]参数用法

          3)、二重指针char  **arrName[]用法

      代码如下:1)、主函数中char **argc参数用法

     1 /* *=+=+=+=+* *** *=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
     2   * 作者代号: *** :guochaoxxl
     3   * 版权声明: *** :(魎魍魅魑)GPL3
     4   * 联络信箱: *** :guochaoxxl@gmail.com
     5   * 文档用途: *** :深入理解C指针
     6   * 文档信息: *** :~/WORKM/StudyCode/CodeStudy/cnblogs_understanding_and_using_c_pointers/chapter1/test05.c
     7   * 修订时间: *** :2017年第39周 10月01日 星期日 上午08:56 (274天)
     8   * 代码说明: *** :演示char **argv用法
     9  * *+=+=+=+=* *** *+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+*/
    10 #include <stdio.h>
    11
    12 int main(int argc, char **argv)
    13 {
    14     for(int i = 0; i < argc; i++){
    15         printf("The main argument %d is %s
    ", i, *(argv + i));
    16     }
    17     printf("
    ");
    18
    19     return 0;
    20 }

      2)、主函数中char *argc[]参数用法

     1 /* *=+=+=+=+* *** *=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
     2   * 作者代号: *** :guochaoxxl
     3   * 版权声明: *** :(魎魍魅魑)GPL3
     4   * 联络信箱: *** :guochaoxxl@gmail.com
     5   * 文档用途: *** :深入理解C指针
     6   * 文档信息: *** :~/WORKM/StudyCode/CodeStudy/cnblogs_understanding_and_using_c_pointers/chapter1/test05.c
     7   * 修订时间: *** :2017年第39周 10月01日 星期日 上午08:56 (274天)
     8   * 代码说明: *** :演示char *argv[]用法
     9  * *+=+=+=+=* *** *+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+*/
    10 #include <stdio.h>
    11
    12 int main(int argc, char *argv[])
    13 {
    14     for(int i = 0; i < argc; i++){
    15         printf("The main argument %d is %s
    ", i, argv[i]);
    16     }
    17     printf("
    ");
    18
    19     return 0;
    20 }

      3)、二重指针char  **arrName[]用法

     1 /* *=+=+=+=+* *** *=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
     2   * 作者代号: *** :guochaoxxl
     3   * 版权声明: *** :(魎魍魅魑)GPL3
     4   * 联络信箱: *** :guochaoxxl@gmail.com
     5   * 文档用途: *** :深入理解C指针
     6   * 文档信息: *** :~/WORKM/StudyCode/CodeStudy/cnblogs_understanding_and_using_c_pointers/chapter1/test07.c
     7   * 修订时间: *** :2017年第39周 10月01日 星期日 上午09:26 (274天)
     8   * 代码说明: *** :演示char **bestBooks[3]的用法
     9  * *+=+=+=+=* *** *+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+*/
    10 #include <stdio.h>
    11
    12 int main(int argc, char **argv)
    13 {
    14     //定义书名的数组
    15     char *titles[] = {"A Tale of Two Cities",
    16         "Wuthering Heights",
    17         "Don Quixote",
    18         "Odyssey",
    19         "Moby-Dick",
    20         "Hamlet",
    21         "Gulliver's Travels",
    22     };
    23     char **bestBooks[3];                                    //最好的图书
    24     char **englishBooks[4];                                 //英文图书
    25
    26     bestBooks[0] = &titles[0];
    27     bestBooks[1] = &titles[3];
    28     bestBooks[2] = &titles[5];
    29
    30     englishBooks[0] = &titles[0];
    31     englishBooks[1] = &titles[1];
    32     englishBooks[2] = &titles[5];
    33     englishBooks[3] = &titles[6];
    34
    35     for(int i = 0; i < 3; i++){
    36         printf("The bestBooks is: %s
    ", *bestBooks[i]);
    37     }
    38     printf("
    ");
    39     for(int j = 0; j < 4; j++){
    40         printf("The englishBooks is: %s
    ", *englishBooks[j]);
    41     }
    42
    43     return 0;
    44 }

      代码都很简单,自行理解即可。

  • 相关阅读:
    jetnuke v1.2安装
    Java Gaming Resources
    @MyEclipse启动Tomcat时Console不显示(已解决+配图)
    在JXSE中,DHT=SRDI
    LINQ 学习笔记9 Kevin
    LINQ 学习笔记6 Kevin
    C# 中自定义事件 Kevin
    LINQ 学习笔记7 Kevin
    C#调用浏览器(默认和非默认浏览器) Kevin
    Section1 Agile Development Kevin
  • 原文地址:https://www.cnblogs.com/guochaoxxl/p/6956518.html
Copyright © 2020-2023  润新知