why malloc doesnot work in my c program?

This question already has an answer here:

  • C, Malloc() and array length [duplicate] 4 answers
  • Do I cast the result of malloc? 27 answers

  • books is a pointer, who's size is 4. You can't read the size of your dynamically created "array".

    You'll see that malloc works, when it doesn't return NULL.


    它打印4,因为这是books的大小(即指针的大小)。


    替代方法:你可以使用一个struct BOOK数组,即struct BOOK books [5000];

    链接地址: http://www.djcxy.com/p/28436.html

    上一篇: 什么是动态铸造的一些“很好用”的例子?

    下一篇: 为什么malloc不能在我的c程序中工作?