C语言--数组与指针--基础易错知识练习笔记 https://tool.lu/coderunner/?id=73R
Notes:着重关注&ints+4,&ip+4的值。
#include <stdio.h>
#include <stdlib.h>
int ints[20] = {
10,20,30,40,50,60,70,80,90,100,
110,120,130,140,150,160,170,180,190,200
};
//int *ints = 0x100;
int *ip = ints + 3;
void main(void) {
printf("ints = %d,ip= %d\n",ints,ip);
printf("ints = %d,ip= %d\n",ints[4],ip[4]);
printf("ints = %d,ip= %d\n",ints+4,ip+4);
printf("ints = %d,ip= %d\n",*ints+4,*ip+4);
printf("ints = %d,ip= %d\n",*(ints+4),*(ip+4));
printf("ints = %d,ip= %d\n",ints[-2],ip[-2]);
printf("ints = %d,ip= %d\n",&ints,&ip);
printf("ints = %d,ip= %d\n",&ints[4],&ip[4]);
printf("ints = %d,ip= %d\n",&ints+4,&ip+4);
printf("ints = %d,ip= %d\n",&ints[-2],&ip[-2]);
//printf("len:%d\n",len);
return 0;
}
运行结果:
ints = 6295648,ip= 6295660
ints = 50,ip= 80
ints = 6295664,ip= 6295676
ints = 14,ip= 44
ints = 50,ip= 80
ints = 0/*非法*/,ip= 20
ints = 6295648,ip= 6295728/*未知*/
ints = 6295664,ip= 6295676
ints = 6295968,ip= 6295760/*未知*/
ints = 6295640/*非法*/,ip= 6295652