博客
关于我
指针第七部分(字符指针数组)---- 2021.3.31
阅读量:271 次
发布时间:2019-03-01

本文共 614 字,大约阅读时间需要 2 分钟。

字符指针数组是一个数组,其中每个元素都是字符指针。字符指针数组的每个元素保存的是对应字符串的首字符的地址。以下是关于字符指针数组的详细分析:

  • 字符指针数组的定义

    • 定义一个字符指针数组num,大小为3,元素分别为"heihei"、"haha"和"xixi"。
    • 代码示例:
      char *num[3] = {"heihei", "haha", "xixi"};
  • 打印字符指针数组中的字符串

    • 使用循环访问num数组中的每个元素并打印。
    • 代码示例:
      for (int i = 0; i < 3; i++) {    printf("%s\n", num[i]);}
  • 访问特定字符

    • 打印"haha"中的第二个字符'a',需要访问num[1] + 1的位置并取内容。
    • 代码示例:
      printf("%c\n", *(num[1] + 1));
  • 定义二级指针保存数组首元素地址

    • 定义二级指针变量p,指向num数组的首元素。
    • 代码示例:
      char **p = num;
  • 通过二级指针打印字符串

    • 打印num数组首元素指向的字符串。
    • 代码示例:
      printf("%s\n", *p);
  • 打印特定位置的字符

    • 打印"haha"中的第三个字符'h',需要访问num[1] + 2的位置并取内容。
    • 代码示例:
      printf("%c\n", *(*(num + 1) + 2));
  • 通过以上方法,可以有效地操作和打印字符指针数组中的各个字符和字符串。

    转载地址:http://zifa.baihongyu.com/

    你可能感兴趣的文章
    NMAP网络扫描工具的安装与使用
    查看>>
    NN&DL4.3 Getting your matrix dimensions right
    查看>>
    NN&DL4.8 What does this have to do with the brain?
    查看>>
    No 'Access-Control-Allow-Origin' header is present on the requested resource.
    查看>>
    No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
    查看>>
    No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
    查看>>
    No module named cv2
    查看>>
    No module named tensorboard.main在安装tensorboardX的时候遇到的问题
    查看>>
    No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
    查看>>
    No new migrations found. Your system is up-to-date.
    查看>>
    No qualifying bean of type XXX found for dependency XXX.
    查看>>
    No resource identifier found for attribute 'srcCompat' in package的解决办法
    查看>>
    No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
    查看>>
    NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
    查看>>
    Node JS: < 一> 初识Node JS
    查看>>
    Node-RED中使用JSON数据建立web网站
    查看>>
    Node-RED中使用node-red-browser-utils节点实现选择Windows操作系统中的文件并实现图片预览
    查看>>
    Node-RED中实现HTML表单提交和获取提交的内容
    查看>>
    Node.js 实现类似于.php,.jsp的服务器页面技术,自动路由
    查看>>
    node.js 怎么新建一个站点端口
    查看>>