title: Do dynamic structs need to be deleted if given value from a function?
body: <p>Sorry if the question is hard to understand but I wasn't sure how to word it.</p>
  <p>Say for example I had a struct like the following,</p>
  <pre><code>struct Days {
         int counter;
  };
  </code></pre>
  <p>And in main I had</p>
  <pre><code>Days *d = new Days;
  d.counter = 0;
  
  </code></pre>
  <p>If I then use <code>d</code> in a loop like this inside main</p>
  <pre><code>do {
     int num = rand()%900+1000;
     d = add(d, num);
  } while(user decides to continue}
  delete d;
  </code></pre>
  <p>where the function <code>add</code> is as follows</p>
  <pre><code>Days *add(Days *d, int num) {
        Days *temp2 = new Days;
        temp2.counter = 0;
        if (d.counter &gt; 0)
            temp2.counter = d.counter;
        temp2.counter += num;
        return temp2;
  ]
  </code></pre>
  <p>Do I need to delete <code>d</code> after each iteration of the do-while loop since its copying over?
  If so, would it be in the <code>add</code> function in the <code>if statement</code> like this</p>
  <pre><code>if (d.counter &gt; 0) {
      temp2.counter = d.counter;
      delete d;
  }
  </code></pre>
  <p>Or would it be in the loop in main?</p>