title: Why does this struct initialization not work (can't return address of local variable)
body: <pre><code>Node *create_node() {
      Node node = malloc(sizeof(Node));
      node.cargo = next_free_cargo++;
      return &amp;node;   
  }
  </code></pre>
  
  <p>I thought malloc created things on the heap? Why is this still considered a local variable?</p>
  
  <p>Also, is this the correct way?</p>
  
  <pre><code>Node *create_node() {
      Node *node = malloc(sizeof(Node*));
      node-&gt;cargo = next_free_cargo++;
      return node;    
  }
  </code></pre>
  
  <p>As I read it, this creates memory for a pointer to a Node.  But how does it allocate memory for the node itself?</p>