转自一CSDN的帖子--http://topic.csdn.net/u/20090922/10/8849db8e-38d3-4e59-aba5-28f7bf0fc55e.html?59748
#include <iostream>
using namespace std;
int main()
{
char str[10] = "afdasf";
int t = sizeof(str);
printf("%d/n", t);
cout < <str < <endl;
memset(str, '1', sizeof(str));
cout < <str < <endl;
return 0;
}
结果如下:
10
afdasf
1111111111烫? //为什么此时str会越界呢?
Press any key to continue
字符串一定要以'/0'结束。不然结果就无法控制了