在C语言中的memset功能 [英] memset function in c language
问题描述
我现在正在研究的memset的功能,但所有的例子就为char数组如下:
I am studying the memset function now, but all the examples are regarding to char array as following:
char a[100];
memset(a, 0, 100);
将在这个字符数组的每个元素设置为0。
it will set every element in this char array to 0.
我想知道,如果memset的可应用于int数组或浮点数组?
I wondered if memset can apply to int array or float array?
推荐答案
是的,它可以适用于任何内存缓冲区,但你必须输入正确的内存缓冲区大小... memset的
对待任何内存缓冲区为一系列字节,所以无论是字符
, INT
,浮动
,双击
等,其实并不重要。记住,虽然这将不设置多字节类型到一个特定的非零值...例如:
Yes, it can apply to any memory buffer, but you must input the correct memory buffer size ... memset
treats any memory buffer as a series of bytes, so whether it's char
, int
, float
, double
, etc, doesn't really matter. Keep in mind though that it will not set multi-byte types to a specific non-zero value ... for example:
int a[100];
memset(a, 1, sizeof(a));
将不可以设置的每个成员 A
来的价值1 ...而是将设置的的每一个字节的由 A
带到了 1
内存缓冲区,这意味着每四个字节 INT
将值设置为 0x01010101
,这是不一样的 00000001
will not set each member of a
to the value 1 ... rather it will set every byte in the memory buffer taken up by a
to 1
, which means every four-byte int
will be set to the value 0x01010101
, which is not the same as 0x00000001
这篇关于在C语言中的memset功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!