請看下面的代碼處理realloc中的指針?
char *line = (char *) malloc(100);
char *newline,*source = line;
int size=100;
newline = realloc (line , size +=size);
// assuming that newline has been successfully assigned the demanded memory and line is freed
現在我在這裏的問題是,我可以在未來表達寫出這樣
source = newline +(line - source);
我有一點懷疑,因爲我使用的是line
指針是在realloc()
成功運行後釋放,但我的程序(這只是它的一個片段)是
仍然在工作嗎?所以可以安全使用line
指針a過去realloc()
已經完成了嗎?
錯誤:應該是char * newline,* source = line;' – avmohan
'newline +(line + 10)'不會編譯,它試圖將兩個指針加在一起。 – interjay