69,382
社区成员
发帖
与我相关
我的任务
分享
#include <memory.h>
int main()
{
wchar_t texts[2][25][80];
wchar_t (*p_old)[25][80] = &texts[0];
wchar_t (*p_new)[25][80] = &texts[1];
wchar_t (*tmp)[80] = p_new[24];
if (memcmp(tmp,p_new[24],sizeof(wchar_t)*80) == 0)
{
//do something
}
return 0;
}
int main()
{
wchar_t texts[2][25][80];
wchar_t (*p_old)[25][80] = &texts[0];
wchar_t (*p_new)[25][80] = &texts[1];
wchar_t (*tmp)[80] = &p_new[24][0];
if (memcmp(tmp,p_new[24],sizeof(wchar_t)*80) == 0)
{
//do something
}
return 0;
}
int main()
{
wchar_t texts[2][25][80];
wchar_t (*p_old)[25][80] = &texts[0];
wchar_t (*p_new)[25][80] = &texts[1];
wchar_t (*tmp)[80] = &(*p_new)[24];
if (memcmp(tmp,(*p_new)[24],sizeof(wchar_t)*80) == 0)
{
//do something
}
return 0;
}
1 #include <stdio.h>
1 #include <stdlib.h>
2 #include <memory.h>
3
4 //typedef short wchar_t;
5
6 int main(void)
7 {
8 wchar_t texts[2][25][80] = { //the length of array is 2
9 | { //the length of the array is 25
10 | | {'h', 'o'}, //The length of the array is 80
11 | | {'w', 'o'},
12 | | {'b', 'e'},
13 | | {'b', 'e'},
14 | | {'b', 'e'},
15 | | {'b', 'e'},
16 | | {'b', 'e'},
17 | | {'b', 'e'},
18 | | {'b', 'e'},
19 | | {'b', 'e'},
20 | | {'b', 'e'},
21 | | {'b', 'e'},
22 | },
23 | {
24 | | {'h', 'o'},
25 | | {'w', 'o'},
26 | | {'b', 'e'}
27 | }
28 };
>> 29 wchar_t (*p_old)[25][80] = &texts[0];
30 wchar_t (*p_new)[25][80] = &texts[1]; //or texts+1
31 wchar_t (*tmp)[80] = p_new[0]; //tmp is two dimensional array, or wchar_t (*tmp)[80] = p_new[1];
32 //wchar_t (*tmp)[80] = p_new[24]; //p_new is out of bounds
33
34 if (memcmp(tmp,p_new[24],sizeof(wchar_t)*80) == 0)
35 {
36 | //do something
37 }
38
39 return 0;
40 }
个人理解,tmp是一个二维数组,只是比普通二维数组特殊一点,其行数是80,所以,p_new[24]赋值tmp是越界的,只能是p_new[0]或者p_new[1]赋值给tmp