I have a simple question in understanding the pointers and struct definitions in the linked list code.
1)
typedef struct node
{
struct node* next;
int val;
}node;
here if I use two “node” when i initialize node *head; which node I am referring to?
2) Here I use an int val in the struct. If I use a void* instead of int is there any thing thats going to change ?
3)Also if I pass to a function
reverse(node* head)
{
node* temp = head; or node* temp = *head;
//what is the difference between the two
}
I am sorry if these are silly question I am new to c language.
Thanks & Regards,
Brett
<1>
in C you need to specify struct node for structs
the last ‘node’ is variable of type struct node
e.g.
and not a type.
if you want to use ‘node’ as a type you need to write
<2>
if you use void* you will need a mechanism to handle what the pointers point to e.g. if void* points to an integer you need keep the integer either on the stack or the heap.
<3>
reverse(node* head)
head is a pointer to your list, *head is the content of what the pointer points to (first node below)
EDIT: rephrased and edited.
EDITx2: apparently the question got edited and a typedef was added so the question was altered.