zoukankan      html  css  js  c++  java
  • C基础--二重指针和数组指针

    #include <stdio.h>
    
    int main1(void)
    {
        int a = 3;
        int b = 8;
        int *p = &a;  // int*  p = &a;  
        int **q;        // int**  q;
        q = &p;
        **q = 10;
        *q =  &b;
        **q = 5;
        p = &b;
        *p = 9;
    
        printf("a = %d	b = %d
    ", a, b);
    
        return 0;
    }
    
    //void fun(char *arr[], int n)
    void fun(char **arr, int n)        //二重指针传参时等价于指针数组
    {
        int i;
        for (i = 0; i < n; i++)
            printf("%s
    ", arr[i]);
            //printf("%s
    ", *(arr+i));        //当成二重指针去索引元素
    }
    int main(void)
    {
        char *s[3] = {"hello", "world", "xwp"};
        fun(s, 3);
        return 0;
    }
    #include <stdio.h>
    
    int main1(void)
    {
        int a[10] = {1,2,3,4,5,6,7,8,9,0};
        //int *p;
        int (*p)[10];    //先算小括号,p和*结合,属于指针类型,指针指向拥有10个int型元素的数组
        //p = a;        int *p; p = a;            a + 1
        p = &a;            //int (*p)[10] = &a;   &a + 1        p+1  加过40个字节
    
        printf("%d	%d
    ", sizeof(p), sizeof(*p));
        printf("%d
    ", (*p)[3]);
        
    
        return 0;
    }
    
    int main2(void)
    {
        /*
        char str[3][20] = {"hello", "world", "itcast"};
        char (*p)[20];
    
        p = &str[0];
        printf("%s
    ", *(p+1));
        */
    /*
        char str[3][20] = {"hello", "world", "itcast"};
        char *p;
    
        p = str[0];
        //printf("%s
    ", p);
        printf("%s
    ", (p+20));
        */
        char str[3][20] = {"hello", "world", "itcast"};
        char (*p)[20];
        p = str;
        printf("%s
    ", *(p+1));
        return 0;
    }
    //void fun(char a[][20], int n)    //数组指针传参时等价于二维数组
    void fun(char (*a)[20], int n)
    {
        int i;
        for (i = 0; i < n; i++)
            scanf("%s", a[i]);
        return;
    }
    int main(void)
    {
        int i;
        char s[3][20];
        fun(s, 3);
        for (i = 0; i < 3; i++)
            printf("%s
    ", s[i]);
    
        return 0;
    }
  • 相关阅读:
    设计模式(简述)
    sql注入防御
    两个防SQL注入过滤代码
    SQL注入实战利用“dbo”获得SQL管理权限和系统权限
    SQL注入技术和跨站脚本攻击的检测
    蓝雨设计整站SQL注入漏洞
    SQL注入攻击零距离
    菜鸟入门级:SQL注入攻击
    三步堵死SQL注入漏洞
    终极防范SQL注入漏洞
  • 原文地址:https://www.cnblogs.com/zhuyaguang/p/4831181.html
Copyright © 2011-2022 走看看