Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Let's look at a simple example first:</p> <pre><code>int a; a = 5; </code></pre> <p>In a sense the integer <strong>a</strong> has two values assoicated with it. The one you most likely think about first is the rvalue, which in this case is the number 5. There is also what is called an lvalue (pronounced "el value") which is the memory address the integer <strong>a</strong> is located at.</p> <p>This is an important concept to grasp. At the end of the day everything is all about memory. We store code and variables in memory. The CPU executes instructions which are located in memory and it performs actions on data which is also in memory. It's all just memory. Nothing very complicated; if someone tries to scare you with pointers don't listen, it's all just memory :)</p> <p>Alrighty so, in the case of an array we are dealing with a contiguious block of memory that is used for storing data of the same type:</p> <pre><code>int array[] = {0, 1, 1, 2, 3, 5, 8, 13, 21}; </code></pre> <p>As you have already noted the name of the array refers to the memory location of the first element in the array (e.g. array == &amp;array[0]). So in my example array above &amp;array[2] would refer to the memory location (or lvalue) that contains the third element in the array.</p> <p>To answer your other question &amp;array is just another memory address, see if this code snippet helps clear up what it points to :)</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; int array[] = {0, 1, 1, 2, 3, 5, 8, 13, 21}; int main(void) { printf("&amp;array[2] is: %p\n", &amp;array[2]); printf("&amp;array[0] is: %p\n", &amp;array[0]); printf("&amp;array is: %14p\n", &amp;array); exit(0); } % gcc test.c % ./a.out &amp;array[2] is: 0x100001088 &amp;array[0] is: 0x100001080 &amp;array is: 0x100001080 </code></pre>
 

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