例1:
#include<stdio.h> #include<stdlib.h> int main(int argc, int*argv[]) { int a[3][2] = { (0, 1), (2, 3), (4, 5) };//看成是一个一维数组,每个元素是大小为2的整型 int*p; p = a[0]; printf("%d\n", p[0]); system("pause"); return 0; }
结果:
1
请按任意键继续. . .
例2:
#include<stdio.h> #include<stdlib.h> int main() { int a[5][5]; int(*p)[4]; p = a; printf("a_ptr=%#p\np_ptr=%#p\n",&a[4][2],&p[4][2]); printf("%p,%d\n", &p[4][2] - &a[4][2], &p[4][2] - &a[4][2]); system("pause"); return 0; }
结果:
a_ptr=0X001DFC78
p_ptr=0X001DFC68
FFFFFFFC,-4
请按任意键继续. . .
例3:
#include<stdio.h> #include<stdlib.h> int main() { int aa[2][5] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int*ptr1 = (int*)(&aa + 1); int*ptr2 = (int*)(*(aa + 1)); printf("%d %d\n", *(ptr1 - 1), *(ptr2 - 1)); system("pause"); return 0; }
结果:
10 5
请按任意键继续. . .
时间: 2024-11-08 19:23:04