int main()
{
node * head=NULL;//What exactly are we doing in this statement. Are we calling the node class that we created before and creating its objects dynamically? And so that means that head object will have two members data and next?
insertAtHead(head,2);
}
insertAtHead(node *&head, int data)//over here again I am not clear on function definition part related to node, can you tell what’s happening?I don’t get what is the meaning of using both * and & symbol ?
Doubt in linked list concept
hello @isingh the first what you have written is exactly correct for nodehead that is we are defining it of type class as it will have two members data and the next.
‘&’ it is used to when you want to pass any data structure by reference that means any change made their will be reflected back and otherwise on every call it will copy the previous and in the new so that is time taking.
i will refer you to watch the pointer section in your course so that you can be more clear with the * and &.
'’ means that: It means that you’re passing it a pointer to a character, which usually means that pointer points to the first of the sequence/
if you still have any doubt you can ask here
Happy Learning!!
I have gone through the pointer section, but i am not still not clear about this part “node*&head”, when we just say “node*head”,are we referring to node class object? So when I add & symbol to it, what change is exactly happening? As & symbol represents address of a pointer?
Hello @isingh here it means that you are passing it by reference yes that means that you are passing the address so every change will be reflected back in the main or the main sequence in the main memory but the same will not be done when you will pass it without this’&’.
if you still have any doubt you can ask here:
Happy Learning!!
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.