Note that there are some explanatory texts on larger screens.

plurals
  1. POPointer of array of structure
    primarykey
    data
    text
    <p>Ok, I've got this code :</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #define ARR_SIZE 5 struct mys { double first; unsigned long second; char str[10]; }; int main(int argc, char** argv) { size_t i = 0; struct mys thes[ARR_SIZE] = { {1.1, 1, "First"}, {2.2, 2, "Second"}, {3.3, 3, "Third"}, {4.4, 4, "Fourth"}, {5.5, 5, "Fifth"} };//load array of structures with values for (; i &lt; ARR_SIZE; ++i) fprintf(stdout, "second-&gt;%lu\n", thes[i].second);//loop through array thes and print element second return (EXIT_SUCCESS); } </code></pre> <p>Now, I want to get the address of the element called second of the zeroth element thes and then use that to loop through the array thes and print each second element.</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #define ARR_SIZE 5 struct mys { double first; unsigned long second; char str[10]; }; int main(int argc, char** argv) { size_t i = 0; unsigned long * ptr = NULL;//pointer to unsigned long struct mys thes[ARR_SIZE] = { {1.1, 1, "First"}, {2.2, 2, "Second"}, {3.3, 3, "Third"}, {4.4, 4, "Fourth"}, {5.5, 5, "Fifth"} }; //first loop for (; i &lt; ARR_SIZE; ++i) fprintf(stdout, "second-&gt;%lu\n", thes[i].second); ptr = &amp;thes[0].second;//get the address of the second element of the zero'th array structure and store it in ptr // Now I want to use the above pointer ptr to loop through the array thes and display the second element like I did above, but I can't manage to do that. //The output of this loop should be the same as the first loop return (EXIT_SUCCESS); } </code></pre> <p>So, I've implemented the pointer but I'm having problem writing the code for the second loop. Any help is appreciated.</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.
 

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