*Note: This is not a duplicate question, since the answer you refer to does not answer my question. I know what malloc() and calloc() should do, but wonder why there doesn't seem to be a difference when using it with Virtual Machine.
I know what the difference should be - malloc() just allocate you the memory, while calloc() initialize it with 0's.
The thing is, in my code it doesn't show up, and malloc() doesn't seem to be giving any difference while running from my Virtual Machine Ubuntu. I ran it a few times, and malloc acts exactly like calloc.
Note - I just checked it with my actual hard drive, and it seems to work ok, there I do get different results.
The code:
#include <stdio.h>
#include <stdlib.h>
int main(){
int i,n;
float *ptr1, *ptr2;
printf("enter a total number of float items: ");
scanf("%d", &n);
ptr1 = malloc(n*sizeof(float));
ptr2 = calloc(n, sizeof(float));
printf("malloc | calloc\n");
printf("----------------------\n");
for(i=0;i<n;i++)
printf("%-10f %10f\n", *(ptr1+i), *(ptr2+i));
printf("\n");
free(ptr1);
free(ptr2);
return 0;
}