I was playing around with alloc functions in my Ubuntu 14.04 64-bit, gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) and found that malloc returns memory with initializing it to zero. Which is quite weird as it should not initialize and the returned memory block should be uninitialized.
The code is as follows:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int *i=(int*)malloc(4);
printf("The Address of pointer is %p and Value is %d\n",i,*i);
return 0;
}
Output is:
The Address of pointer is 0x843070 and Value is 0
I have also tried with assigning big chunks of memory with the same result. Can anyone suggest why this is happening?