数组和指针
程序代码:
#include<iostream.h> char *GetMemory1() { char *p="hello world"; return p; } char *GetMemory2() { char p[]="hello world"; return p; } void main() { char *str1 = NULL; char *str2 = NULL; str1 = GetMemory1(); str2 = GetMemory2(); cout<<str1<<endl<<str2<<endl; }
为啥GetMemory2在返回时就成乱码了?