我尝试 realloc 但它没有用
这是代码。感谢您的帮助
trial = malloc (4 * sizeof(int));
trial[0] = 1; trial[1] = 4;trial[2] = 7;trial[3] = 11;
trial = (int*)realloc(trial, sizeof(int) * 5);
trial[sizeof(trial)-1] = 23;
int a;
for(a = 0; a < sizeof(trial); a++){
printf("TRIAL %d \n", trial[a]);
}
输出看起来像这样
TRIAL 1
TRIAL 4
TRIAL 7
TRIAL 23
它应该是
TRIAL 1
TRIAL 4
TRIAL 7
TRIAL 11
TRIAL 23