title: How to code memory diagram?
body: <p>I was asked to code this memory diagram:</p>
  
  <p><a href="https://i.stack.imgur.com/b7TP3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/b7TP3.png" alt="memory diagram"></a></p>
  
  <p>I was also given this struct: </p>
  
  <pre><code>struct product {
      char *name;
      double price;
      int stock_count;
  };
  typedef struct product PRODUCT;
  </code></pre>
  
  <p>I don't have to write the complete function just the required statements and write an array from the heap that can store two products, with the first product initialized as shown; i.e., with information about pies.</p>
  
  <p>this is what I tried to do:
  for item</p>
  
  <pre><code>PRODUCT item;
  item-&gt;name = "bread"; //not sure if it's "bread" or &amp;"bread"
  item-&gt;price = 2.25;
  item-&gt;stock_count = 45;
  </code></pre>
  
  <p>for the array from the heap that can store
  two products:</p>
  
  <pre><code>PRODUCT *inventory, *p;
  p = malloc(sizeof(PRODUCT)*2);
  assert(p!=NULL);
  inventory = p; //I've also read that the answer might be p = inventory not sure why though
  </code></pre>
  
  <p>but i'm not sure how to change the [0] show in the memory diagram where the name is "pie",price is 9.50 and stock_count is 7.</p>
  
  <p>and if possible can someone write over the memory diagram for what would happen to it if </p>
  
  <pre><code>PRODUCT *p;
  p = &amp;inventory[1];
  *p = item;
  </code></pre>
  
  <p>was executed?</p>