怎么回事啊,难道程序错了?
#include"stdio.h"#include"iostream.h"
char *getmemory(void)
{
char p[]="hello word";
return p;
}
void main()
{
char *str=NULL;
str=getmemory();
printf(str);
getchar();
}
结果是:hell@ .为什么不是:hello word
2010-05-24 15:09
2010-05-25 19:35
2010-05-25 20:57
程序代码:#include"iostream.h"
#include<stdio.h>
#include<string.h>
char* getmemory(void)
{
char*p;
p=new char[50];
strcpy(p,"hello,world!");
return p;
}
void main()
{
char *str=NULL;
str=getmemory();
printf(str);
getchar();
delete[] str; //这句不能少,否则容易发生内存泄露!
}
2010-05-26 02:29
2010-05-26 17:13
2010-05-26 17:20
2010-05-26 19:08
2010-05-26 19:43
2010-05-27 11:22