title: Why is the address of the same pointer different?
body: <p>I was trying linked list on C++ and when I try to print the data of the list, it gives funny result which tells me that the list is null. When I print the address of the variable in main and print the address of the parameter of the same variable in the function, it gives different results. Could anyone please explain it for me, thank you!
  Here is the code:</p>
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  typedef struct link_node{
      int data;
      link_node* next;
  };
  
  void iter(link_node* head){
      link_node* cur = head;
      cout&lt;&lt;&quot;The address of head in function: &quot;&lt;&lt;&amp;head&lt;&lt;endl;
      while(cur!=NULL){
          cur = cur-&gt;next;
          cout&lt;&lt;cur-&gt;data&lt;&lt;' ';        
      }
  }
  
  link_node *create(int a){
      link_node* head;
      link_node* cur;
      head =(link_node*) malloc(sizeof(link_node));
      cur = head;
      for(int i=a;i&lt;a+10;i+=2){
          link_node * node = (link_node*) malloc(sizeof(link_node));
          node-&gt;data = i;
          cur-&gt;next = node;
          cur = node;
      }
      cur-&gt;next = NULL;
      return head;
  }
  
  int main(){
      link_node* head_1 = create(0);
      link_node* head_2 = create(1);
      link_node* result = (link_node*) malloc(sizeof(link_node));
      cout&lt;&lt;&quot;The address of head_1: &quot;&lt;&lt;&amp;head_1&lt;&lt;endl;
      iter(head_1);
  
      return 0;    
  }
  </code></pre>
  <p>And here is the output of the program:</p>
  <pre><code>The address of head_1: 0x61ff04
  The address of head in function: 0x61fef0
  0 2 4 6 8
  </code></pre>
  <p>Thanks!</p>