此数组分配的 3D 版本似乎工作正常,但添加第四个维度显然会导致段错误。编辑:(事实证明指针的东西很好,只是内部循环中有一对拼写错误)
\n\n #include <stdio.h>\n #include <stdlib.h>\n\n #define M 2\n #define N 3\n #define O 4\n #define P 5\n\n int main()\n {\n int ****A = malloc(sizeof(int***)*M);\n int i, j, k, m;\n\n if(!A) \n {\n printf (" **** Out of Memory");\n }\n for(i = 0; i < M; i++)\n {\n A[i] = malloc(sizeof(int**)*N);\n if(!A[i]) \n {\n printf(" *** Out of Memory");\n }\n for(j = 0; j < N; j++)\n {\n A[i][j] = malloc(sizeof(int*)*O);\n if(!A[i][j]) \n {\n printf(" ** Out of …Run Code Online (Sandbox Code Playgroud) 调试器没有错误或警告,但是内存清理程序显示“未初始化的访问”,每行输出一个。
输出是可以的,除非我更改了数组的大小或注释掉了一个我什至无法访问的数组(char ArrayThatINeverEvenUsed [10000]),否则输出是意外的。未初始化的访问错误会同时出现在正确/预期的版本和错误的版本中。
#include <stdio.h>
int main()
{
FILE *fptr;
fptr = fopen("ID_List29.csv", "wb");
// why does this program only work if there's an UNUSED array of size ~100000 or larger
char ArrayThatINeverEvenUsed[10000]; // why does removing zeros cause different outputs?
int i , j, k , m;
int sz = 0;
char c, d, e, f;
char tStr[8];
tStr[4] = 0x7C; // pipe separator
tStr[5] = 0x7C;
tStr[6] = 0x0D;
tStr[7] = 0x0A;
for(i = 65; i < …Run Code Online (Sandbox Code Playgroud) c ×2