#include<iostream>
using namespace std;
int main()
{
char str1[] = "abcdefg";
memset(str1,'x', 3);
cout << str1 << endl;
int i, a[4];
for(i = 0; i < 4; i++)
cout << a[i] << "\t";
cout << endl;
memset(a, 0, sizeof(a) - 4);
for(i = 0; i < 4; i++)
cout << a[i] << "\t";
cout << endl;
memset(a, 0, sizeof(a));
for(i = 0; i < 4; i++)
cout << a[i] << "\t";
cout << endl;
return 0;
}
结果为:
xxxdefg
-858993460 -858993460 -858993460 -858993460
0 0 0 -858993460
0 0 0 0
#include<iostream>
using namespace std;
int main()
{
char dst[100] = "hello world!";
char src[10] = "C++";
memcpy(dst, src, strlen(src));
cout << dst << endl;
memcpy(dst, src, strlen(src) + 1);
cout << dst << endl;
memcpy(dst + strlen(dst), src, strlen(src) + 1);
cout << dst << endl;
return 0;
}
结果为:
C++lo world!
C++
C++C++