请看下面的代码处理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