C:用memset功能 [英] C: Using memset function
问题描述
这是code,我想尝试写:
This is the code that I want to try to write:
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
int main(int argc, char *argv[])
{
float arry[3] = {0};
memset(arry, (int) 10.0, 3*sizeof(float));
return 0;
}
我的问题是,我想看看是否有可能使用的memset使数组中的每个条目比0。但是其他的一些,通过该行加强后,数组内容更改为极少数( 0)。我不知道我在做什么错在这种情况下,与使用memset的()函数。我希望这不是一个重复的职位,因为没有为我打字这似乎是建议相关的问题。
My problem is that I want to see if it's possible to use memset to make every entry of an array to be a number other than 0. However, After stepping through that line, the array contents change to a very small number (0). I wonder what I'm doing wrong in this case with using the memset() function. I hope this isn't a duplicate post, as none of the suggested related questions as I'm typing this appears to be.
推荐答案
铸造双为int只是创建二进制数00001010(10二进制),这是memset'ed值。因为它是一个字符,每个彩车是实际接收的位模式00001010 00001010 00001010 00001010。
Casting a double to an int just creates the binary number 00001010 (10 in binary), and that is the value that is memset'ed. Since it's a char, each of your floats is actually receiving the bit pattern 00001010 00001010 00001010 00001010.
这篇关于C:用memset功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!