If we have an array[5], we know that arr == &arr[0]
but what is &arr[2] = ?
Also, what does &arr return to us?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Let’s look at a simple example first:
In a sense the integer a 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 a is located at.
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 🙂
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:
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 == &array[0]). So in my example array
above &array[2] would refer to the memory location (or lvalue) that contains the
third element in the array.
To answer your other question &array is just another memory address, see if
this code snippet helps clear up what it points to 🙂