一,场景一
int arr[4] = {10, 20, 30, 40};
int (*pp)[4] = &arr;
int* p = (int*)(pp + 1);
NSLog(@"%d", *(p-2)); // 结果:30
二,场景二
int arr[4] = {10, 20, 30, 40};
int (*pp)[4] = &arr;
double* p = (double*)(pp + 1);
NSLog(@"%d", *(int*)(p - 2)); // 结果:10
int arr2[2][4] = {
{10, 20, 30, 40},
{11, 21, 31, 41}
};
int (*pp2)[4] = &arr2[1];
NSLog(@"%d", *(int*)pp2); // 结果:11
double* p2 = (double*)pp2;
NSLog(@"%d", *(int*)(p2 + 1)); // 结果:31
int* p2p = (int*)(arr2 + 1);
NSLog(@"%d", *(p2p - 3)); // 结果:20
时间: 2024-10-08 11:13:24