When malloc run, it generate memory block, which doesn't set any value and it contains garbage values. When calloc run, some event happened like a malloc function but there is one difference. When calloc generate new block, it sets 0(Zero) in the block.
#include <stdio.h>
#include <stdlib.h>
int main(void){
int i,j;
int* array1 = (int*)malloc(sizeof(int)*5);
int* array2 = (int*)calloc(sizeof(int),5);
for(i = 0; i < 5; i++){
printf("%p: %d\n",&array1[i],array1[i]);
}
printf("===================\n");
for(j = 0; j < 5; j++){
printf("%p: %d\n",&array2[j],array2[j]);
}
return 0;
}
According to this information, first five values must contain garbage values (Actually it should look like random data), second five values must be zero. However when this code was run in Windows, there is no problem, but when this code was run in Linux, this condition doesn't procure. I thought it depend ASLR or DEP protection, and I shut down ASLR and I used old Linux system for DEP protection, but result is same. Finally, I thought that it may depend C Standard and I changed C Standard when Code was compiled but result is not different. I'm asking that what is the reason.