title: Trouble visualizing the stack and heap
body: <p>I apologize if this is too much code to post, I will delete this if that it is the case. My code below compiles and runs fine but I am unsure if I am allocating memory in the correct spots. Particularly, task 7 and 8. Task 7 should be an array of 10 pointers allocated on the
  stack with each pointer referring to 10 unique instances allocated on the heap. Task 8 should be a single pointer allocated on the stack with the pointer referring to an array of 10 instances allocated on the heap. I feel like I have done task 7 and 8 backwards. As you can probably tell this is an assignment and I'm not looking for direct answers. I would just like to know if I'm on the right track for task 7 and 8.</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  #define SIZE 10
  
  
  /* Task 1 -- add typedef and rename to Point3d */
  
  typedef struct POINT_3D
  {
      int x_cord;
      int y_cord;
      int z_cord;
  } Point3d;
  
  /*Add function prototypes here*/
  
  
  void init_Point1(Point3d* pt);
  
  Point3d init_Point2(Point3d pt);
  
  void PrintPoint1 (Point3d *pt);
  
  void PrintPoint2(Point3d pt);
  
  
  int main()
  {
      int i;
      Point3d pt1;
      /* Task 2 -- using proper operator give values (5,4,2) to pt1
         and use the proper Print function to print it */
      pt1.x_cord = 5;
      pt1.y_cord = 4;
      pt1.z_cord = 2;
  
      printf(&quot;Printing Point3d:&quot;);
      PrintPoint1(&amp;pt1);
  
      /*Task 3 -- Declare a pointer of type Point3d named ptr1*/
      Point3d  *ptr1;
  
  
      /*Task 4 -- Allocate memory for ptr1 and initialize it by
      calling init_Point1() function and use the proper Print function to print it */
      ptr1 = (Point3d*) malloc(sizeof(Point3d));
      init_Point1(ptr1);
  
      printf(&quot;Printing Point3d:&quot;);
      PrintPoint1(ptr1);
  
      //Declaring second variable pt2
  
      Point3d pt2;
  
      /*Task 5 and 6 -- Compelete init_Point2 function and
       call it with pt2 to create a point with random coordinates)
       , use the proper Print function to print it*/
      init_Point2 (pt2);
  
  
      printf(&quot;Printing Point3d:&quot;);
      PrintPoint2(pt2);
  
  /************************************************/
  /*************** Part 2 *************************/
  /************************************************/
      /* All three variables p1, p2, and p3 are intended to be used as *
       * some form of array of the struct type declared above.         */
  
      Point3d p1[SIZE];
      Point3d* p2[SIZE];
      Point3d* p3;
  
  
  
  
      printf (&quot;Calling init_Point1()\n&quot;);
      for (i = 0 ; i &lt; SIZE; ++i)
      {
          printf (&quot;For position %d\n&quot;, i);
          init_Point1 (&amp;p1[i]);
          PrintPoint1(&amp;p1[i]);
          //PrintPoint2(p1[i])
      }
  
  
  /*Task 7 -- Repeat the same steps for array p2, you must call a
     proper init function and display the results by calling Print function */
  
  /***********************************/
  /* p2 : Declare, Initialize, Print */
  /***********************************/
  
      printf (&quot;Calling init_Point1()\n&quot;);
      for ( i = 0; i &lt; SIZE; i++)
      {
          p2[i] = (Point3d*) malloc(sizeof(Point3d));
          printf (&quot;For position %d\n&quot;, i);
          init_Point1 (p2[i]);
          PrintPoint1 (p2[i]);
      }
  
  
  
  
  
  /* Task 8 -- p3 is a single pointer that must refer to an array of 10 instances
     allocated on the heap. Repeat the previous steps for p3 by initializing and
    printing using proper functions*/
  
  /***********************************/
  /* p3 : Declare, Initialize, Print */
  /***********************************/
  
  p3 = (Point3d*) malloc(sizeof(Point3d)*SIZE);
  
  
      printf (&quot;Calling init_Point1()\n&quot;);
      for ( i = 0; i &lt; SIZE; i++)
      {
          printf (&quot;For position %d\n&quot;, i);
          init_Point1 (&amp;p3[i]);
          PrintPoint1 (&amp;p3[i]);
      }
  
  
  
  
      return 0;
  }
  
  
  /************************/
  /* function definitions */
  /************************/
  
  
  void init_Point1 (Point3d *pt)
  {
      pt-&gt;x_cord = rand() % 100;
      pt-&gt;y_cord = rand() % 1000;
      pt-&gt;z_cord = rand() % 100;
  
  }
  
  /* Task 5 - write init_Point2() function definition */
  
  Point3d init_Point2 (Point3d pt)
  {
      pt.x_cord = rand() % 100;
      pt.y_cord = rand() % 1000;
      pt.z_cord = rand() % 100;
  
      return pt;
  }
  
  
  
  void PrintPoint1 (Point3d *pt)
  {
      printf(&quot;\t(x %d , y %d , z  %d ) \t&quot;, pt-&gt;x_cord, pt-&gt;y_cord, pt-&gt;z_cord);
      printf(&quot;\n&quot;);
  
  }
  
  void PrintPoint2 (Point3d pt)
  {
  
      printf(&quot;\t(x %d , y %d , z  %d ) \t&quot;, pt.x_cord, pt.y_cord, pt.z_cord);
      printf(&quot;\n&quot;);
  
  }
  </code></pre>