[問題] 請問將0分配至malloc

看板C_and_CPP作者時間11年前 (2013/02/14 14:24), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串1/1
#include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { char *ptr; (ptr = (char *)malloc(0)); if (ptr == NULL) puts("Got a null pointer"); else puts("Got a valid pointer"); system("pause"); return 0; } 想請問為什麼答案會是 got a valid pointer malloc(0)不就代表ptr沒有被分配到任何的記憶體大小嗎 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.36.201.242

02/14 14:46, , 1F
Implementation defined
02/14 14:46, 1F

02/14 14:47, , 2F
02/14 14:47, 2F
文章代碼(AID): #1H78C1Mi (C_and_CPP)