khuang8493
9/13/2018 - 12:48 AM

The name of an array is a pointer

The name of an array is actually a pointer variable that stores the memory address of the first element of the array.

An array's name, is actually just a pointer to its first element. So that means the array name is a pointer variable that stores the address of the first element of the array. So if the array name is 'arr', the arr[i] is the ith element in this array, the address of this element is: arr + i;

So if 's' is a string, which is really an array of char. So 's' is the name of this array s[i];

If we want to print each character in this string 's':

// print string, one character per line
    for (int i = 0, n = strlen(s); i < n; i++)
    {
        printf("%c\n", *(s + i));
    }
    
So the *(s+i) is the same as writing as s[i]. They work exactly the same, just different way of writing the code.
 
"printf("%c\n", *(s + i));" means: print out the char at the location or address of "s" or "s+i".
* means the memory address of something.
*(s+i): with the * at the front means: go to that address, and get the value stored in that memory address.