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);
    }
  • 相关阅读:
    分页SQL 和Oracle 存储过程
    什么是SilverLight
    opendpi 源码分析(一)
    Multiway arrays
    循环链表
    轮询算法 这是一个印度人写的,学习下。 来自 codeproject
    Friday the Thirteenth
    通过命令行指定监听的IP和端口
    pthread_key_t
    贝叶斯网络 未学习前数据结构
  • 原文地址:https://www.cnblogs.com/hzhida/p/2805704.html
Copyright © 2011-2022 走看看