Just remember
that data
items/elements of an array are stored in consecutive memory locations (i.e., a[0] contains an
element and (a + 0) contains an address of this element). So, if we apply pointer operator (*) on
it, it will give the value stored at this address—that is,
*(a + 0) = the value stored at the 0th location
So,
*(a + 0) is equivalent to a[0]
*(a + 1) is equivalent to a[1]
Please note that internally C converts a[i] as *(a + i). Therefore, the following notations
refer to the same element:
a[i];
*(a + i);
*(i + a);
i[num];
These are all the same.
Note that we cannot write the following statement:
*(a++); //is invalid
This is because you cannot increment an address. But you can increment a pointer that holds
an address.
Here, ‘a’ holds the address of the first element of the array. So if we increment the base
address, the compiler cannot determine the first location of this array.
Do'stlaringiz bilan baham: |