Hello people,
I am making a program to add nodes to create a linked list, and to display it. At first when I ran the code in the main itself, there were no problems.
This worked fine and displayed it too. But when I decided to make it a function and pass the pointers as parameters, it ran the function part, but when it came back to main, it did not do the display part.
createlist takes it's parameters by value. Any changes made to them are not reflected on the variables in the calling code, so on line 37 you dereference a null pointer.
You could pass the pointers by reference: void createlist(node*& ptr, node*& top, node*& bot)
I really thought that passing pointers necessarily meant that they were passed by reference
In general, that is correct. However, that is only true for the data pointed to by the pointers: The pointers themselves are copied. That is why if you want to modify the actual pointers, they need to be passed by reference.