gpt4 book ai didi

c - 指针 calloc 函数是否返回一个指针 vector ? (C语言)

转载 作者:太空宇宙 更新时间:2023-11-04 08:49:42 27 4
gpt4 key购买 nike

我试图理解一个 c 代码,(SimpleScalar,bpred.c),有一点让我很困惑:

    int *shiftregs;
shiftregs = calloc(1, sizeof(int));

int l1index, l2index;
l1index = 0;
l2index = shiftregs[l1index];

我删除了一些可能无济于事的代码。 calloc调用后,*shiftregs变成指针数组? l2index 的值是多少?非常感谢!

最佳答案

因为 shiftregs 是一个指向 int 的指针,所以 *shiftregs 是一个 int

由于 calloc 保证它分配的内存设置为 0,并且您已经分配了足够的内存来引用 shiftregs[0]l2index 将为 0(假设 calloc 没有失败并返回 NULL)。

关于c - 指针 calloc 函数是否返回一个指针 vector ? (C语言),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20110548/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com