title: ANSI C do you have to use malloc() when creating a struct?
body: <p>Let's say I have this <code>struct</code> in ANSI C:</p>
  
  <pre><code>typedef struct _point
  {
      float x;
      float y;
  } Point;
  </code></pre>
  
  <p>and this function to create this <code>struct</code>:</p>
  
  <pre><code>Point createpoint(float x, float y)
  {
      Point p;
      p.x = x;
      p.y = y;
      return p; 
  }
  </code></pre>
  
  <p>This allows me to create a <code>struct</code> with this function i.e:</p>
  
  <pre><code>int main()
  {
      Point pointOne = createpoint(5, 6);  
      Point pointTwo = createpoint(10, 4);
      float distance = calculatedistancefunc(pointOne, pointTwo);
  
      /* ...other stuff */
  
      return 0;
  }
  </code></pre>
  
  <p>Someone told me that this code is not valid, because the <code>struct</code> does not get <code>malloc</code>'d in the <code>createpoint(float x, float y)</code> function before it gets returned, and that the <code>struct</code> will be deleted. 
  However, when I use my <code>struct</code> like this, it doesn't seem to get deleted.</p>
  
  <p>So my question is:
  do I have to <code>malloc</code> this <code>struct</code>, and why? / why not?</p>