标签:style blog color ar sp div on 问题 log
1 #include"string.h" 2 #include"malloc.h" 3 4 5 void swap(int a,int b) 6 { 7 int temp; 8 temp=a; 9 a=b; 10 b=temp; 11 } 12 13 int get_int(int a) 14 { 15 int i=1+a; 16 return i; 17 } 18 19 char* get_memory0() 20 { 21 char* p=(char*)malloc(sizeof(char)*20); 22 strcpy(p,"hello world"); 23 return p; 24 } 25 26 char* get_memory1() 27 { 28 char* p="hello world"; 29 return p; 30 } 31 char* get_memory2() 32 { 33 char p[]="hello world"; 34 return p; 35 } 36 37 void main() 38 { 39 int x=4,y=3; 40 swap(x,y); 41 int z=x-y; 42 printf("z=%d\n",z);//问题1 43 44 z=get_int(z); 45 printf("z=%d\n",z);//问题2 46 47 char* c0 = get_memory0(); 48 printf("c0=%s\n",c0);//问题3 49 50 const char* c1=get_memory1(); 51 printf("c1=%s\n",c1);//问题4 52 53 char* const c2=get_memory2(); 54 printf("c2=%s\n",c2);//问题5 55 56 c1=c2; //6 57 *c1=*c2; //7 58 c2=c1; //8 59 *c2=c1; //9 60 }
标签:style blog color ar sp div on 问题 log
原文地址:http://www.cnblogs.com/dondre/p/4090187.html