摘要: 学习笔记#include<stdio.h>#include<stdlib.h>void f1(int* p);int main(void){ int *p; f1(p); *p=4; printf("%d\n",*p); free(p); return 0;}void f1(int* p){ p=(int*)malloc(sizeof(int)); }改为如下解决,主要是因为函数f1中对p的修改在函数返回时就消失了#include<stdio.h>#include<stdlib.h>void f1(int** p);int m 阅读全文
posted @ 2011-08-24 22:26 郭远威 阅读(326) 评论(1) 推荐(0) 编辑
摘要: 遇到来一个段错误现象,下面自定来一个字符串复制函数,第4行如果换成字符串指针,如char * dest;,就会一直有个段错误现象,而改为字符数组后就没来了,是不是如果所字符串指针的话,相当于没分配内存,后面的操作就有问题!盼高人指点#include<stdio.h>char* strcp(char* strdest,const char*strsrc);int main(void){char dest[20];char* src="hello world!";printf("\n%s\n",strcp(dest,src)); }char* s 阅读全文
posted @ 2011-08-24 12:54 郭远威 阅读(305) 评论(1) 推荐(0) 编辑