zoukankan      html  css  js  c++  java
  • C语言中,指针,引用,二维数组,指针数组,数组指针的解析

    //二维数组的理解
    #include<stdio.h>
    void main()
    {
        int  a[3][3] = {1,2,3,4,5,6,7,8,9};
        int *n[3];                    //这两种声明的方式是一样
        int *(n[3]);                 //指针数组
        int  (*p)[3] = a;            //数组指针,指向数组的指针
        int *m =&a[0][0];
        printf("%x\n",m);
        printf("%x\n",*(p+1));
        printf("%d\n",**(p+1));
        printf("%x\n",*a);
        printf("%x\n", a);
        for(int i=0;i<9;i++)
            printf("%x\n",*(a+i));
        for(int i=0;i<9;i++)
            printf("%d\n", *(*a+i));
        for(int i=0;i<9;i++)
            printf("%d\n",**(a+i));
    }
    
    
    //指针参数也就是一个地址而已
    #include<stdio.h>
    void print(int *q)
    {
        printf("%x\n",q);
        q= q+3;
        printf("%x\n", *q);
    }
    
    void main()
    {
        int b[9] = { 1,2,3,4,5,6,7,8};
        int *p = b;
        printf("%x\n",p);
        print(p);
        printf("%x\n",*p++);
    }
    
    对指针引用的理解
    #include<stdio.h>
    #include <stdlib.h>
    #include <string.h>
    void Malloc(char *&p)
    {
        printf("%x\n",p);
        p  = (char*)malloc(100);
        printf("%x\n",p);
    }
    
    void main()
    {
        char *str = NULL;
        str = (char*)malloc(100);
        strcpy(str,"hello");
        printf(str);
        strcpy(str,"world\n");
        printf(str);
        printf("%x\n",str);
        free(str);
        str = NULL;
        printf("%x\n",str);
        Malloc(str);
        strcpy(str,"hello");
        printf(str);
    }
  • 相关阅读:
    轮播图适应代码jQ
    jQuery focus、blur事件 添加、删除类名
    节点操作js jQuery
    动态加载jQuery
    底边滑动变色的列表
    节点选择只有链接
    第三方登录过程—OAuth2.0协议
    JavaScript中常谈的对象
    浅谈JavaSccript函数与对象
    JavaScript与DOM的关系
  • 原文地址:https://www.cnblogs.com/hzhida/p/2805704.html
Copyright © 2011-2022 走看看