Note that there are some explanatory texts on larger screens.

plurals
  1. POPart 1: Referencing an Array Without Using Pointers and only Subscripting | Part 2: "..." with Pointers
    primarykey
    data
    text
    <pre><code>#include &lt;iostream&gt; #include &lt;time.h&gt; using namespace std; void my_func(); int main() { float start_time = clock(); cout &lt;&lt; "Starting time of clock: " &lt;&lt; start_time; cout &lt;&lt; endl &lt;&lt; endl; for (int i = 0; i &lt; 100000; i++) { my_func(); } float end_time = clock(); cout &lt;&lt; "Ending time of clock: " &lt;&lt; end_time; cout &lt;&lt; endl &lt;&lt; endl; } void my_func() { int my_array[5][5]; } </code></pre> <p>I need to write a program that does a large number of references to elements of a two-dimensional array, using only subscripting. This is really a two-part project, but I'm only concerned with getting the first part right. The second part allows the use of pointers but for now, I am only subject to "subscripting" (indices?). Any advice on how to proceed?</p> <p>I have successfully completed the first part thanks to Volkan İlbeyli. I am now moving on to the second part:</p> <p>I need to write a program that does a large number of references to elements of a two-dimensional array, using pointers and pointer arithmetic. Here's what I have so far:</p> <pre><code>#include &lt;iostream&gt; #include &lt;time.h&gt; using namespace std; void my_func(); int main() { float start = clock(); for (int i = 0; i &lt; 100000; i ++) { my_func(); } float end = clock(); cout &lt;&lt; "Ending time of clock: " &lt;&lt; (end - start) / ((double)CLOCKS_PER_SEC); } void my_func() { int my_array[10][10]; for (int i = 0; i &lt; 10; i++) { for (int j = 0; j &lt; 10; j++) { *(my_array+i+j); } } } </code></pre> <p>I have done the first part and now I am working on the next part. I just want to know if I've missed anything. The code works fine and so does the program. Pointers are not my strongpoint and it took me a lot of time on the Internet to find my answers. Asking for a technical standpoint now on pointers and "pointer arithmetic".</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.
 

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