Hello everybody,
I would like to use memset to initialize allocated memory to zero. However it does not work as expected.
#include <acknex.h>
#include <default.c>
void main()
{
// allocate memory for 100 integers
int *array = (int *)malloc(100 * sizeof(int));
// initialize memory
memset(array, 0, 100 * sizeof(int));
// display int #3 on the screen (should be zero, but isn't)
error(str_for_num(NULL, *(array + 2)));
}
In this example 'array' should be initialized to zero, but it isn't: It still contains random values.
What am I doing wrong here?
Thank you!