我有以下代码
#include<stdio.h>
int main () {
void *result[20];
void *endptr;
void *x;
for (i = 0; i < 20; i++) {
result[i] = malloc(10);
printf("111 : %d\n",result[i]);
}
endptr= sbrk(0);
printf("\n222 : %d\n",endptr);
x = malloc(60); ----------- error
return 0;
}
我想打印所有 void 指针的数值以及 sbrk 函数调用 form malloc 的次数?
如果我在 printf 语句中打印 *endptr,它会报错。目前我认为它会打印分配内存的地址。 %x 只是将当前值转换为十六进制并正确打印吗?
x = malloc(60) 也给出错误:void value not ignored as it should be 我该怎么做?
谢谢
最佳答案
sbrk(0) 返回“程序中断”的当前大小,它实际上不是一个指针,因此取消引用它会出错。
关于c - c 中的 sbrk 和 malloc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23091416/