指针运算

来源:互联网 发布:知乎45回答 编辑:程序博客网 时间:2024/05/22 07:59

先看如下例子:

#include "stdio.h"int main(){int *p = (int*)1000;int *q = (int*)2000;printf("p = %d,q = %d \n",p,q);printf("%d\n",p-q);return 0;}


运行结果:

p = 1000, q = 2000;

p - q = -250;

 

说明:指针的运算是按它指向的变量所占用的内存单元字节数进行运算。

在上例中,p++ 即为 1004

 

原创粉丝点击