摘要: 1,void GetMemory(char *p, int num){ p = (char *)malloc(sizeof(char) * num);}void Test(void){ char *str = NULL; GetMemory(str, 100); // str 仍然为 NULL strcpy(str, "hello"); // 运行错误} 原因:编译器总是要为函数的每个参数制作临时副本,指针参数p的副本是_p,编译器使_p = p。如果函数体内的程序修改了_p的内容,就导致参数p的内容作相应的修改。这就是指针可以用作输出参数的原因。在本例中,_p申请了新的内 阅读全文
posted @ 2012-04-23 22:35 foreverlearn 阅读(445) 评论(0) 推荐(0) 编辑
摘要: 1:函数原型void * memcpy ( void * destination, const void * source, size_t num );函数作用参考:http://www.cplusplus.com/reference/clibrary/cstring/memcpy/Copy block of memoryCopies the values ofnumbytes from the location pointed bysourcedirectly to the memory block pointed bydestination.The underlying type of t 阅读全文
posted @ 2012-04-23 13:34 foreverlearn 阅读(945) 评论(1) 推荐(0) 编辑