Page 44 - C-Language
P. 44
As a special case, observe that &(arr[0]) is equivalent to &*(arr + 0), which simplifies to arr. All of
those expressions are interchangeable wherever the last decays to a pointer. This simply
expresses again that an array decays to a pointer to its first element.
In contrast, if the address-of operator is applied to an array of type T[N] (i.e. &arr) then the result
has type T (*)[N] and points to the whole array. This is distinct from a pointer to the first array
element at least with respect to pointer arithmetic, which is defined in terms of the size of the
pointed-to type.
Function parameters are not arrays.
void foo(int a[], int n);
void foo(int *a, int n);
Although the first declaration of foo uses array-like syntax for parameter a, such syntax is used to
declare a function parameter declares that parameter as a pointer to the array's element type.
Thus, the second signature for foo() is semantically identical to the first. This corresponds to the
decay of array values to pointers where they appear as arguments to a function call, such that if a
variable and a function parameter are declared with the same array type then that variable's value
is suitable for use in a function call as the argument associated with the parameter.
Examples
Declaring and initializing an array
The general syntax for declaring a one-dimensional array is
type arrName[size];
where type could be any built-in type or user-defined types such as structures, arrName is a user-
defined identifier, and size is an integer constant.
Declaring an array (an array of 10 int variables in this case) is done like this:
int array[10];
it now holds indeterminate values. To ensure it holds zero values while declaring, you can do this:
int array[10] = {0};
Arrays can also have initializers, this example declares an array of 10 int's, where the first 3 int's
will contain the values 1, 2, 3, all other values will be zero:
int array[10] = {1, 2, 3};
In the above method of initialization, the first value in the list will be assigned to the first member of
the array, the second value will be assigned to the second member of the array and so on. If the
https://riptutorial.com/ 20

