Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>int v[elements]; </code></pre> <p>This create a fresh array of integers.</p> <p>It is relatively difficult to pass around arrays, as you have to be careful how you handle the allocation of memory, and they hark back to the old days of <code>C</code>.</p> <p>As you're learning <code>C++</code> you can use a <code>class</code> to manage memory issues. <a href="http://en.cppreference.com/w/cpp/container/vector" rel="nofollow"><code>std::vector</code></a> is syntactically similar to an array, but looks after allocation and resizing for you, and remembers what size it is, too.</p> <p>You can pass objects into functions by reference <code>&amp;</code>, and inside the function it will be able to modify the passed in object, and have a lasting effect after the function has finished.</p> <pre><code>void read(vector&lt;int&gt;&amp; elements) { // in here you can resize the vector } void print(const vector&lt;int&gt;&amp; elements) { // passing in elements by const reference means you can't modify it } </code></pre> <p>So altogether:</p> <pre><code>int main() { vector&lt;int&gt; elements; read(elements); print(elements); } </code></pre> <p>Alternatively, if you want to be object oriented, you should be looking for ways of grouping data and functions together, so that you avoid passing around data altogether. In this case you can group the vector and the read and print functions. Maybe call it <code>UserIntegers</code>:</p> <pre><code>class UserIntegers { public: void process() { read(); print(); } private: vector&lt;int&gt; numbers; }; </code></pre> <p>Usage:</p> <pre><code>int main() { UserIntegers userIntegers; userIntegers.process(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload