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)
.
精彩评论