Structure pointer assignment in C++
<p>What's wrong with this code, specially in check function? I assigned the address of <code>temp1</code> in the root pointer array. But I can't access it from the main function, although they gave the same address as output.</p>

<pre><code>struct block {
  int counter=0;
  struct block *arr[4];
  bool is_leaf;
  string val[3];

} root;

void check() {
  struct block temp1;
  temp1.is_leaf=true;
  temp1.val[0]="Sy";
  root.arr[1]=&amp;temp1;
  cout&lt;&lt;root.arr[1]-&gt;val[0]&lt;&lt;endl;
  cout&lt;&lt;root.arr[1]&lt;&lt;endl; //block address
}

int main(){

  string s1;

  root.val[2]=s1;
  struct block temp;
  temp.val[0]="wewrq";
  root.arr[0]=&amp;temp;
  check();
  cout&lt;&lt;root.arr[0]-&gt;val[0]&lt;&lt;endl;  // did work
  cout&lt;&lt;root.arr[1]&lt;&lt;endl;          // same block address
  cout&lt;&lt;root.arr[1]-&gt;val[0]&lt;&lt;endl;  // didn't work
}
</code></pre>