Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
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)”?上帝之手?;)
Because you are assigning to lw calloc(...) == 0, which is false. You want it the other way around
calloc(...) == 0
false
Replace ==0)) with )==NULL).
==0))
)==NULL)