Need to initialize array after malloc?

Greetings,
I usually have to deal with large 2D arrays. Before using them, I need to reset all the value to 0:
1
2
double* arr= (double*) malloc(height*width*sizeof(double));
for (int i=0; i<height*width; i++) {arr[i]= 0;}

However, this loop is time-consuming. I notice that in Release mode, normally the arrays' values are already 0 without any initialization.

Do I really need to reset all the value to 0 after memory allocation? Are the values automatically 0 after memory allocation? Thanks..
man wrote:
The malloc() function allocates size bytes and returns a pointer to the allocated memory. The memory is not initialized.
The calloc() function allocates memory for an array of nmemb elements of size bytes each and returns a pointer to the allocated memory. The memory is set to zero.
Great!, thanks ne555
Topic archived. No new replies allowed.