C和指针之二维字符串数组用指针数组、数组指针、二级指针打印
        【摘要】  1、问题 
  二位字符串数组用指针数组、数组指针、二级指针打印 
 
    
 
    
 
    
 
 2、测试代码 
 
 #include <stdio.h> int main(){  char value[4][5] = {"chen", "yu", "feng", "yy"}; char *p[5]; ch...
    
    
    
    1、问题
  二位字符串数组用指针数组、数组指针、二级指针打印 
 2、测试代码
   
    - 
     
      
     
     
      
       #include <stdio.h>
      
     
- 
     
      
     
     
       
      
     
- 
     
      
     
     
      
       int main()
      
     
- 
     
      
     
     
      
       {
      
     
- 
     
      
     
     
       
      
     
- 
     
      
     
     
      
        char value[4][5] = {"chen", "yu", "feng", "yy"};
      
     
- 
     
      
     
     
      
        char *p[5];
      
     
- 
     
      
     
     
      
        char (*p1)[5];
      
     
- 
     
      
     
     
      
        char **p2;
      
     
- 
     
      
     
     
       
      
     
- 
     
      
     
     
      
        //把二位数组的值赋给指针数组
      
     
- 
     
      
     
     
      
        for (int i = 0; i < 4; i++)
      
     
- 
     
      
     
     
      
        {
      
     
- 
     
      
     
     
      
        printf("value[%d] is %s\n", i, value[i]);
      
     
- 
     
      
     
     
      
        p[i] = value[i];
      
     
- 
     
      
     
     
      
        }
      
     
- 
     
      
     
     
      
        for (int i = 0; i < 4; i++)
      
     
- 
     
      
     
     
      
        {
      
     
- 
     
      
     
     
      
        printf("p[%d] value is %s\n", i, p[i]);
      
     
- 
     
      
     
     
      
        }
      
     
- 
     
      
     
     
      
        //把value赋给数组指针
      
     
- 
     
      
     
     
      
        p1 = value;
      
     
- 
     
      
     
     
      
        for (int i = 0; i < 4; i++)
      
     
- 
     
      
     
     
      
        {
      
     
- 
     
      
     
     
      
        printf("value1 is %s\n", p1[i]);
      
     
- 
     
      
     
     
      
        printf("value2 is %s\n", *(p1 + i));
      
     
- 
     
      
     
     
      
        }
      
     
- 
     
      
     
     
      
        //把p赋值为二级指针
      
     
- 
     
      
     
     
      
        p2 = p;
      
     
- 
     
      
     
     
      
        for (int i = 0; i < 4; i++)
      
     
- 
     
      
     
     
      
        {
      
     
- 
     
      
     
     
      
        printf("value3 is %s\n", *(p2 + i));
      
     
- 
     
      
     
     
      
        }
      
     
- 
     
      
     
     
      
        
      
     
  文章来源: chenyu.blog.csdn.net,作者:chen.yu,版权归原作者所有,如需转载,请联系作者。
原文链接:chenyu.blog.csdn.net/article/details/78514157
        【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
            cloudbbs@huaweicloud.com
        
        
        
        
        
        
        - 点赞
- 收藏
- 关注作者
 
             
           
评论(0)