原帖由 wanghongyang 于 2011-4-22 16:20 发表
为了巩固坛友们的C语言知识,我将以后不定期的将我遇到的各种C语言问题或者我见到的比较好的问题以这种竟答的方式展示给大家,依赖是希望大家上论坛能多学点知识,二来是希望我们论坛可以成为一个knowledge base,大家 ...
See inline comment.char *p=(char *)malloc(sizeof(char)*10);/* This line would allocate 10 bytes of memory, and p is pointed to the address */p="hello";/* String const "hello" is allocated in read-only section (.rodata) in the memory. So that p is changed to this address. It would cause two problems: 1, The allocated 10 bytes of memory is leaked, because of we doesn't know the address, so we cannot free it. 2, If anyone modified the string which p pointed to, it would cause system exception. */