Here is my code
Node* Node::createNode(int n)
{
Node newNode(n);
Node *temp = &newNode;
return temp;
}
void Node::printNode(Node* node)
{
cout << node->data << "\t" << node->next << endl;
system("pause");
}
Here is the main function
int main(int argc, char* argv[])
{
Node *head = Node::createNode(10);
Node::printNode(head);
return 0;
}
Problem, I was expecting to print 10. Instead I get a garbage value of -858993460. I have noticed that until the point, parameter is passed into the function, it retains correct value. But inside the function printNode, the value changes. So I guess something is going wrong in the function call. Any help would be appreciated.