源码:
1 #include
2 #include
3
4 using namespace std;
5
6 int main(int argc, char *argv[])
7 {
8 char src[6] = "hello";
9 char dest[5];
10 strcpy(dest,src);
11 cout<<"dest= "<<dest<<endl;
12 cout<<"src= "<<src<<endl;
13 }
运行结果:
~ dest= hello
src=
谁能告诉我,为什么src没有内容输出???
我这里的运行结果
dest= hello
src= hello
Press any key to continue
不但我的VC++如此,在线的gcc的输出也如此
http://codepad.org/GdcdGNe4
dest= hello
src= hello
但是注意,这其实造成缓冲区的溢出了。
数组长度声明不够,缓冲区溢出