指针的计算

image.png
image.png

#include "stdio.h"
int main()
{
    int a = 10;
    int* p = &a;
    printf("%p\n", p);
    printf("%p\n", p + 1);
    printf("%p\n", p + 2);

    return 0;
}

输出结果:

000000799839F9B4
000000799839F9B8
000000799839F9BC

总结:

1.指针+1或者指针-1是什么意思
把指针记录的内存地址,往后或者往前移动一个步长;
2.什么是步长,步长与什么有关
跟数据类型有关
char:1字节
short:2字节
int:4字节
long:4字节
long long:8字节


YingLi
6 声望4 粉丝

From zero to hero.