|
发表于 2019-10-16 10:59:58
|
显示全部楼层
本帖最后由 xypmyp 于 2019-10-16 11:08 编辑
The problem related to how pointer works in 2D array.
- /*
- int i, j, c;
- char arr[3][4] = {
- {"123"},
- {"321"},
- {"213"}
- };
- char* pointerTo2DArray = &arr[0][0];
- */
- int i, j, c;
- char p[10];
- char *arr1[3] = { "123","321","213" };
- char **arr = arr1;
-
- strcpy((char*)((int*)arr +0), (char*)((int*)arr + 1));
- printf("%s %s %s", (char*)*((int*)arr + 0), (char*)*((int*)arr + 1),(char*)*((int*)arr + 2));
- getchar();
- return 0;
复制代码
As the lever 1 address is pointing to a memory address which 4 Byte long = sizeof(int), than you convert it to (char*) which strcpy() required [optional, it's the start address of your string].
|
-
Memory in realtime
-
Output
|