C++ passing a pointer to static function changes value during execution
<p>Here is my code</p>

<pre><code>Node* Node::createNode(int n)
{
    Node newNode(n);
    Node *temp = &amp;newNode;
    return temp;
}

void Node::printNode(Node* node)
{
    cout &lt;&lt; node-&gt;data &lt;&lt; "\t" &lt;&lt; node-&gt;next &lt;&lt; endl;
    system("pause");
}
</code></pre>

<p>Here is the main function</p>

<pre><code>int main(int argc, char* argv[])
{

    Node *head = Node::createNode(10);
    Node::printNode(head);
    return 0;
}
</code></pre>

<p>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.</p>
