标签:组元 告诉 class getc mamicode 运算 数组元素 变量 bsp
void main() { int num = 100; double *p = (double*)#//明明是整型,我非tm按照double解析 printf("指针p指向%x,该地址上存的值为%f\n",p,*p); getchar(); }
unfortunately
p=&a将变量a地址赋予指针p p=&a[i]将数组元素地址赋给指针p p=a[10]将数组首元素地址赋给指针p p1=p2指针p2赋值给指针p1
#include<stdio.h> #include<stdlib.h> void main() { int a[10] = {0,1,2,3,4,5,6,7,8,9}; for (int i = 0; i<10; i++) { printf("a+i=%x,&a[i]=%x\n", a + i, &a[i]); } getchar(); }
输出结果:
不难得出,a即代表首元素地址a+i意味着在首地址的基础上推进i个元素a+i=&a[i]=======>*(a+i)=a[i]
所以一种很拽的写法是
#include<stdio.h> #include<stdlib.h> void main() { int a[10] = {0,1,2,3,4,5,6,7,8,9};for (int *p = a; p < a + 10; p++) { *p = 9 - *p; printf("\n%d", *p); } getchar(); }
输出结果:
标签:组元 告诉 class getc mamicode 运算 数组元素 变量 bsp
原文地址:https://www.cnblogs.com/saintdingspage/p/11946442.html