菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
444
0

C lang:Pointer and Array

原创
05/13 14:22
阅读数 96046

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.

发表评论

0/200
444 点赞
0 评论
收藏