I am still confused with the two functions malloc() and calloc()
As we know calloc() initialize the memory it allocates while malloc() doesn't.
But when I tried the following code, the result seemed unexpected.
typedef struct{
int *val;
}Node;
int main()
{
Node *q=(Node*)malloc(sizeof(Node));
if(q->val==NULL) printf("malloc initialized memory\n");
Node *p=(Node*)calloc(1,sizeof(Node));
if(p->val==NULL) printf("calloc initialized memory\n");
}
The variables 'val' of val of p and q are both NULL. Isn't q->val uninitialized? Can anyone explain it to me? Thanks!