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 \n",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.\n", 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.\n", 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.

Guess you like

Origin www.cnblogs.com/enomothem/p/11907520.html