What's the point of malloc(0)?

后端 未结 17 1794
庸人自扰
庸人自扰 2020-11-22 15:40

I just saw this code:

artist = (char *) malloc(0);

...and I was wondering why would one do this?

17条回答
  •  爱一瞬间的悲伤
    2020-11-22 15:55

    Just to correct a false impression here:

    artist = (char *) malloc(0); will never ever return NULL; it's not the same as artist = NULL;. Write a simple program and compare artist with NULL. if (artist == NULL) is false and if (artist) is true.

提交回复
热议问题