C程序和指针的概念

时间:2019-03-21 09:33:39

标签: c pointers calloc

我正在尝试理解下面的程序摘录,以编写内存布局。但是我很困惑。

exportBase64(context, type, callback) {
    context.$http.get(config.api_url + config.export_path + type
    )
    .then(response => response.json())
        .then((response) => {
            if (response.file) {

                const txt = atob(response.file);
                const file = new Blob([txt], { type: "application/vnd.ms-excel" });
                const href = URL.createObjectURL(file);

                // success
                callback(context, 'success', href);
            } else {
                // error
                callback(context, 'error');
            }
        })
        .catch(function (err) {
            console.log(err)
        })

}

据我了解,func接受A,它是指向整数指针的指针。另一种查看方法是指向大小为3的整数数组的指针。

#include <stdio.h> #include <stdlib.h> int *A[3]; int x=4; int y; void func(int** A, int x); main() { int x = 3; func(A,x); } void func(int **A,int x) { if (x) { A[x - 1] = (int*) calloc(x, sizeof(int)); func(A, x - 1); } return; } 这部分让我感到困惑。 A[x-1] =(int*) calloc(x,sizeof(int))将在堆中分配3个字节并返回一个指针。

那么我们如何允许将指针分配给指针指针?

我们为什么使用calloc

还通过将rhs分配给A [x-1]我们打算做什么?

0 个答案:

没有答案