Whats is the problem?

Head function gets altered even though i am passing it to rev function by value and not by reference

bro!
even thought u dont not pass head as reference but u are updating the links in the reverse function so the head is being updated.

due to link updationg the head is linked list is getting updated

then what is the difference between passiing it by reference or value?

passing it by reference means that u are updating the value at the address
by value means that temporary updated are made in the function call

I mean what difference does it make in this case

bro there will be no difference
since u are updating the links pass it by value or by reference your head is getting updated

How can that be. Why would i pass it by reference if it gets updated otherwise also?

and if it did, then wouldnt the print function in my code alter head node?

void reverse(node* head)
{
Node* current = head;
Node *prev = NULL, *next = NULL;

    while (current != NULL) { 
        next = current->next; 
        current->next = prev; 
        prev = current; 
        current = next; 
    } 
    head = prev; 
} 

tell me one thing this is a code of reversing the linked list
i am passing head as value and not as refernce in function paramter
if in the int main() function u try printing the linked list wont the reverse be printed

like when the links are being updated how do u expect the head not getting changed

print function is just traversing the LL using the head node

but in the print function also head is updated to head->next at each step

brrrooooo
u are changing the link

u are updating the internal linked the linked are reverseddd…
please try the reverse function on pen paper u update the links
in the print u just vo ahead, u aint reversing any link

okay i got it.
Thanks

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.