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);
    }
  • 相关阅读:
    golang json用法讲解
    go操作redis
    go 操作 kafka
    go指针:unsafe.Pointer
    初学者GO 之旅 (1) 包、变量、函数
    mac iterm2 安装 lrzsz rz sz命令
    golang工具之present
    php 安装 kafka 扩展
    elasticsearch 安装中文分词器
    Centos7 安装 elasticsearch-head插件
  • 原文地址:https://www.cnblogs.com/hzhida/p/2805704.html
Copyright © 2011-2022 走看看