Creating multiple structs in one for loop


<p>So I have a loop that goes something like</p>

<pre><code>for (r = 0; r &lt; k; r++) {
    pair p = {r, D[r]};
    queue.push(p);
}
</code></pre>

<p>where pair is defined as</p>

<pre><code>struct pair {
    int u;
    float d;
}
</code></pre>

<p>Is this a legal way to create k pairs and push them onto a priority queue?  Do the pairs still exist on the queue in their original form even though p gets overwritten each time?  Or does each pair that's already on the queue get automatically updated to the new value of p, resulting in a queue full of identical copies of the same pair?</p>

<p>Thanks!</p>
