Here is my struct definition:-
struct Node{
void *data;
struct Node *left;
struct Node *right;
};
If I allocate memory for this struct using malloc, will the pointer variables be NULL?
int main(int argc, char** argv){
Node *node = malloc(sizeof(struct Node));
if(node->left == NULL){
//Is it guaranteed to be NULL?
}
return 0;
}
>Solution :
Section 7.22.3.4 The malloc Function
The standard states:
#include <stdlib.h> void *malloc(size_t size);Description
The malloc function allocates space for an object whose size is
specified by size and whose value is indeterminate.
It means that the content of the memory allocated by malloc cannot be determined.
//Is it guaranteed to be NULL?
No, it is not and assuming it may invoke undefined behaviour.