开发者

Calloc simple problem

char* lw;
if((lw=(char *)calloc(2, sizeof(char))==0)) 
   printf("Failed to allocate.\n"); 
else 
   printf("a开发者_开发问答llocated %p\n", lw);

I've read manual for calloc, need a quick and brief answer, why does it output NIL? It goes to else, so lw cannot possibly be NIL, then outputs "allocated (nil)"? God's hand? ;)


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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜