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;
}
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.
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.