在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/C/ c語(yǔ)言里malloc返回NULL是什么意思?

c語(yǔ)言里malloc返回NULL是什么意思?

在讀一本數(shù)據(jù)結(jié)構(gòu)的書(shū) 經(jīng)常出現(xiàn)類似
int *a;
if((a=malloc(size))==NULL)
xxx...

這是什么意思?

回答
編輯回答
憶當(dāng)年
malloc returns a void pointer to the allocated space, or NULL if there is insufficient memory available. To return a pointer to a type other than void, use a type cast on the return value. The storage space pointed to by the return value is guaranteed to be suitably aligned for storage of any type of object. If size is 0, malloc allocates a zero-length item in the heap and returns a valid pointer to that item. Always check the return from malloc, even if the amount of memory requested is small.

malloc 返回一個(gè)指向已分配空間的 void 指針,如果內(nèi)存不足,則返回 NULL。若要返回指向非 void 類型的指針,請(qǐng)?jiān)诜祷刂瞪鲜褂妙愋娃D(zhuǎn)換。由返回值指向的存儲(chǔ)空間保證適當(dāng)?shù)貙?duì)齊以存儲(chǔ)任何類型的對(duì)象。如果 size 是 0,malloc 會(huì)在堆中分配一個(gè)零長(zhǎng)度的項(xiàng)目,并返回一個(gè)指向該項(xiàng)目的有效指針。即使請(qǐng)求的內(nèi)存量很小,也要始終檢查 malloc 的返回值。

2018年7月31日 08:29
編輯回答
拼未來(lái)

在動(dòng)態(tài)分配內(nèi)存是的時(shí)候失敗了

2018年4月10日 10:03