I am writing a code to make a linked list. one of the function I wrote in order to make a linked list easier in the main function was[node is the name of a struct conatains a.data b.pointer name next) :
node& create_node(int value)
{
node newitem;
newitem.data=value;
newitem.next=NULL;
return (newitem);
};
When I write the function like this everything is ok but I want to write the function header as :
node * create_node(int value)
But when I write it that way and I write
return *newitem;
I get an error. I wanted to ask why the VS shows me an error in the 2nd way and what is the difference between using * and & [I already read here about references but I don't understand why one should use it in functions as , from what I understood using references takes additional space and not contributing ] .
edit :thank you for help, when I posted this it was before I even ran a test on the main function only tried to avoid mistakes before compilation . It took me some time but now I see the fundamental mistake I did .