0
char* lw;
if((lw=(char *)calloc(2, sizeof(char))==0)) 
   printf("Failed to allocate.\n"); 
else 
   printf("allocated %p\n", lw);

我已经阅读了 calloc 的手册,需要一个快速而简短的答案,为什么它输出 NIL?它转到else,所以lw不可能是NIL,然后输出“已分配(nil)”?上帝之手?;)

4

1 回答 1

2

Because you are assigning to lw calloc(...) == 0, which is false. You want it the other way around

Replace ==0)) with )==NULL).

于 2011-09-15T13:22:59.773 回答