zoukankan      html  css  js  c++  java
  • C lang:Pointer and Array

    Xx_Introduction

    Point and Array germane.

    Xx_Code

    #include<stdio.h>
    #define SIZE 4
    int main(void)
    {
        short arra[SIZE];
        short * a;
        double arrb[SIZE];
        int i;
        double * b;
    
        a = arra;
        b = arrb;
    
        for (i = 0; i < SIZE; i++)
            printf("%d %p %p 
    ",i ,a + i,b + i);
        return 0;
    }
    

    Ax_Address and Value

    dates + 2 == &dates[2];    //true    address
    *(dates + 2) == dates[2];    //true   value
    *dates + 2 = (*dates) + 2; // Beause '*' > '+'
    

    <<<<<<<<<<"I am the dividing line ">>>>>>>>>>>>

    Bx_Replace

    x-a not use pointer

    #include<stdio.h>
    #define M 12
    
    int main(void)
    {
        int days[M] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
        int i;
    
        for (i = 0; i < M; i++)
            printf("Month %2d has %2d days.
    ", i + 1, days[i]);
        return 0;
    }
    
    

    x-b use pointer

    #include<stdio.h>
    #define M 12
    
    int main(void)
    {
        int days[M] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
        int i;
    
        for (i = 0; i < M; i++)
            printf("Month %2d has %2d days.
    ", i + 1, *(days + i));        // equal to days[i]
        return 0;
    }
    

    x-c Notice

    V.V(vice versa)Use arrays to represent Pointers,but attention to

    When an array is a function of an argument.

  • 相关阅读:
    centos7.5搭建zabbix3.4.x以及mysql定制化监控
    dockerfile 的常用讲解
    使用nginx快速搭建文件服务器
    centos7 安装ELK
    centos7 安装Gitlab
    centos7 安装jenkins
    ansible-playbook使用详解
    DNS主从配置
    ansible 安装部署文档
    WPF Grid MouseWheel事件无法触发
  • 原文地址:https://www.cnblogs.com/enomothem/p/11907520.html
Copyright © 2011-2022 走看看