编程问题求助,求一下程序的输出结果,并分析。
珞石 2018-12-28 06:52:50 /**
程序1
*/
#include<stdio.h>
#include<stdlib.h> //malloc等需要使用
#include<string.h> //strcpy等需要使用
void GetMemory3(char **p3,int num);
void Test3(void);
void GetMemory3(char **p3,int num){
*p3=(char*)malloc(num);
}
void Test3(){
char *str3=NULL;
GetMemory3(&str3,100);
strcpy(str3,"hello");
printf("%s\n",str3);
printf("\n");
}
int main(){
Test3();
return 0;
}
/**程序2*/
#include<string.h> //strcpy
#include<stdio.h>
#include<stdlib.h>
void Test4(void);
int main(){
Test4();
return 0;
}
void Test4(){
char *str4=NULL;
str4=(char*)malloc(100);
strcpy(str4,"world");
printf("%s\n",str4);
printf("\n");
}