小编Naf*_*man的帖子

为什么不重新分配工作

我在一个更大的项目中遇到了这个问题,其中由于某种原因,该realloc函数绝对没有任何作用.我错过了一些明显的东西吗

这是一个简化的例子:

#include <stdio.h>
#include <string.h>

int main()
{
    int x = 1, y = 2, z = 3;
    int* arr, *arr1;
    int** arra;

    arra = (int**)malloc(sizeof(int*));
    arr = (int*)malloc(sizeof(int));
    arr[0] = x;
    arra[0] = arr;
    arra = (int*)realloc(arra, sizeof(int*) + sizeof(int*));
    arr1 = (int*)malloc(sizeof(int));
    arr1[0] = y;
    arra[1] = arr1;

}
Run Code Online (Sandbox Code Playgroud)

当我调试时,最后的arra结果是{{1}},即使我的理解应该是{{1},{2}}.

c arrays realloc

2
推荐指数
1
解决办法
260
查看次数

标签 统计

arrays ×1

c ×1

realloc ×1