I would like to know how to declare, allocate and initialize array of Node to null.
typedef struct Nodes_Of_List {
int data;
struct Nodes_Of_List *next;
} Node;
//declare array of head nodes
Node *table;
//ALOCATE memory for "x" x is provided at runtime, number of head nodes
table = malloc(sizeof(Node) * x);
//Initialize elements to Null value
?? //How to do it
Explanation regarding initializing dynamic array of head nodes of linked list to Null requested. Purpose is to make array of linked lists, to make a hashtable.
Nodewhat you mean by ahead node? Or do you need another structure such astypedef struct Head_Node { Node *head; Node *tail; } Head_Node;? (Note that the 'tags' namespace is separate from the ordinary identifiers namespace, sostruct Head_Nodedoes not conflict withHead_Node.) You define an array of whatever type it is the same way as you define an array ofint— except you use a different type name. Ifxis a variable rather than a constant, you usemalloc()to allocate the memory. Usingcalloc()will (de facto if not de jure) initialize the allocated memory to null.table->data = NULL; table->next = NULL;dataelement is anint, it would be best not to useNULLbut just0to initialize it.