If the prototype of my function is void sell_item(store **head,store **tail). In main i've passed sell_item(&head,&tail), where head & tail where both pointers of store(struct) type.
Now I want to access the the content where head is pointing to. How shall I access it? Like *head->next??? But this is not working.
where next is another member of store storing pointing to the next location of memory (pointing to next node).
The question you should be asking is why is the prototype of your function accepting a pointer to a pointer to a struct or type store?
If head and tails are pointers to store ( aka Store * head, *tail ) don't you think your prototype should reflect that? void sell_item(store * head, store * tail) ?
That way you could access the information in head & tail like so..
@georgewashere Passing a pointer by copy won't allow the pointers to be reassigned if the 1st(head) or last(tail) node are deleted.
The pointers must be passed either by reference, or by passing a pointer to each pointer. I prefer pass by reference because it simplifies the syntax of their usage in the function.
Pass by reference:
1 2 3 4
void sell_item(store*& head, store*& tail)// hey!! How do we know what to sell here (LB's point)?
{
head = head->next;// 1st node deleted. head reassigned
}