I want to initialize my variable array “test” with memset( ).
int test = NULL;
test = (int)malloc(sizeof(int) *ijmax);
memset(test, 0, sizeof(int) * 100 );
I get correct value when I use 0 as initial value, but I get some strange values when I set initial value to be non-zero values. For example, if I set it to 1,
memset(test, 1, sizeof(int) * 100 );
I will get test[0]=test[1]=…test[99]=16843009. Is there any body know what the problem is? Thanks,
The memset() function writes bytes, not words. So writing 1 to sizeof(int)*100 bytes writes 00000001 to every set of 8-bits. Thus, each integer in binary looks like the following:-