memset、memcpy等mem家族函数

整理一下mem家族函数。

文章目录

memset

这是我最喜欢的函数。初始化为非零的数,或者中途使用的时候直接全部重置。

memcpy

我也喜欢这个函数,整段复制,终于不用for循环挨个复制了。

	char *s = "GoldenGlobalView";
	char d[20];
	memcpy(d, s + 3, 4); //从第13个字符(V)开始复制,连续复制4个字符(View)
	d[4] = '\0'; //memcpy(d,s+12*sizeof(char),4*sizeof(char));也可
	printf("%s", d);
	//------------------------
	float a[5] = {
    
    1.0, 2.0, 3.3, 4.1, 5.2};
	float b[3] = {
    
     0.0f };
	memcpy(b, a+1, 3 * sizeof(float));
	for (int i = 0; i < 3; i++)
	{
    
    
		printf("%f ", b[i]);
	}

おすすめ

転載: blog.csdn.net/u011913417/article/details/116207631