Hi Guys,
I read the following in the FAQ:
Originally Posted by
FAQ
malloc leaves the block of memory uninitialized, but calloc zero fills the memory. This does not mean that
p = calloc ( 1, sizeof ( int * ) );
will result in a pointer to int with a value of NULL. Zero filled memory does not mean that the memory is filled with the data type's equivalent of 0, so this zero fill cannot be relied on except with integral values such as int or char. Pointers and floating point may use a different representation for 0 than all bits zero.
Please tell me if I got it right:
1.
I CAN'T rely on calloc to Zero fill memory with floating points??
Code:
float *pArr;
int i;
for (i=0;i<10;++i)
{
pArr=calloc(sizeof(*pArr),10);
printf("%f\n",pArr[i]);
}
The result I get is 0.
2.
I CAN'T rely on calloc to Zero fill memory where pointers point to??
Code:
float *pArr[10];
int i;
for (i=0;i<10;++i)
{
pArr[i]=calloc(sizeof(float *),10);
printf("%f\n",*pArr[i]);
}
Again the result is 0.
3. CAN I rely that calloc will Zero fill memory for int , char ,long??
Many thanks for your help