zoukankan      html  css  js  c++  java
  • char (*p)[]和char *p[]的区别

    理解的关键在于:

    1. []的优先级高于*,(*p)[]理解为指向一个数组,*(p[])存放指针的数组

    2. char (*p)[SIZE]:指向一维数组的指针,一维数组只能有SIZE个元素

        char *p[SIZE]:指针数组,数组有SIZE个元素

    代码测试:

    1. #include <stdio.h>  
    2. #define TESTSIZE 20  
    3. int main(void)  
    4. {  
    5.     char szTest[][TESTSIZE] = {"hello", "world"};  
    6.     char (*p)[TESTSIZE];  
    7.   
    8.     p = szTest;  
    9.     for(int i = 0; i < sizeof(szTEST)/TESTSIZE; i++)  
    10.     {  
    11.         printf("%s", p + i);  
    12.     }  
    13. }  

      

    1. #include <stdio.h>  
    2. #define STRSIZE 20  
    3.   
    4. int main(void)  
    5. {  
    6.      char *p[] = {"hello", "world!"};                //p[],数组  
    7.      for(int i = 0; i < 2; i++)  
    8.          printf("%s ", p[i]);  
    9.   
    10.      return 0;  
    11. }  
  • 相关阅读:
    Python基础笔记(五)
    Python基础笔记(四)
    Python基础笔记(三)
    Python基础笔记(二)
    Python基础笔记(一)
    分页存储过程
    MD Test
    vue路由的配置技巧
    Echarts的使用与配置项
    js中call,apply,bind之间的区别
  • 原文地址:https://www.cnblogs.com/xiaobingqianrui/p/6513060.html
Copyright © 2011-2022 走看看