0

Help needed in understanding one line;

Here's some part of the code class Node { public: int data; Node * next; }; void push(struct Node ** head_ref, int new_data) { struct Node * new_node = (struct Node * ) malloc(sizeof(struct Node)); new_node->data = new_data; new_node->next = ( * head_ref); ( * head_ref) = new_node; } In this code I didn't get the meaning of "struct Node ** head_ref" (parameter of the push function) why we need the struct keyword when there's already the Node data type.

13th Oct 2021, 1:39 PM
Kashyap Kumar
Kashyap Kumar - avatar
1 Odpowiedź
+ 2
In the push function you are declaring a new variable, so even if you have another Node data type it doesn't count here unless it is a global variable. It's just like int new_data , here even if you have another new_data somewhere you should use int keyword because for this push function it is a new variable and you must declare the data type. While declaring a structure data type you should use struct keyword for every new variable or you can use typedef keyword.
13th Oct 2021, 2:32 PM
Arun Ruban SJ
Arun Ruban SJ - avatar