文章分类 -  C/C++

 
C/C++程序的内存管理
摘要:在处理C内存分派的时候,我们总会毫不犹豫的犯下各种错误,不信的话,你先看看下面几个例子。 例子一: voidGetMemory(char*p) { p=(char*)malloc(100); } voidTest(void) { char*str=NULL; GetMemory(str); strcpy(str,"helloworld"); printf(str); } 请问运行Test函数会有什么样的结果? 答:程序崩溃。因为GetMemory并不能传递动态内存,Test函数中的str一直都是NULL。strcpy(str,"helloworld")将 阅读全文
posted @ 2011-03-25 23:00 1yh 阅读(114) 评论(0) 推荐(1)