Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, even though I could not understand the purpose or the meaning of the task you are attempting, if I didn't get it wrong, you are asked to reach to the elements of the 2D array by using indices. </p> <p>Considering your code, in your <code>my_func()</code> you do <strong>not</strong> access to the elements. You only declare that you will use a 2D array with size 5x5. To access the elements, (i think) in your case to reference the arrays, you should use <code>for</code> loops and indices to access the elements of the array.</p> <p>I should go like this in your case:</p> <pre><code>void my_func() { //assuming that the usage of int my_array[1500][500] = {0}; //square matrice is not mandatory for(int i=0; i&lt;1500 ; i++){ for(int j=0; j&lt;500 ; j++){ my_array[i][j]; //no operation is done, only accessing the element } } return; } </code></pre> <p>You could also swap the for loops to access the array in a vertical manner, i.e. going through first column, then 2nd, then 3rd... That will make your <em>referencing a 2D array by indices</em> slower. See <a href="https://stackoverflow.com/questions/9936132/why-does-the-order-of-the-loops-affect-performance-when-iterating-over-a-2d-arra">this post on SO</a> why it slows down to swap the for loops, i.e. changing the row-column order into column-row.</p> <p>You should also note that <strong>if you are concerned with critical time measuring</strong> of a certain event, you should include only that event when starting the clock and ending the clock. In your code, you also include the time to call <code>cout</code>, <code>endl</code>, and the calling time of <code>my_func()</code> which has nothing to do with the <em>array referencing</em>. Also I'd rather measure the time in the <code>main()</code> function since the <em>accessing the 2D array</em> doesn't require too much code. If it did require too much time, I'd call the function, declare the timing variables inside, definitely not print the starting time, start the time before the repeat-the-operations loop and stop after the loop terminates. You can see <a href="https://stackoverflow.com/questions/10154962/c-how-to-measure-time-correctly">this post</a> to have an idea about how time is measured and printed (when you need to consider seconds, or milliseconds etc.).</p>
    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.
 

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