One Dimensional Array in C

Notes:

One Dimensional Array in C Programming Language:
One Dimensional ( 1-D ) Array in C:
While accessing each element in an array; if it requires only one index or subscript such an array is called 1-dimensional array.
Ex: arrayName[index]

Declaring a one dimensional array:
Syntax:
data_type arrayName[size];
Ex:
int numbers[5]; // numbers is an array; which can hold 5 integer values

Note: With respect to one dimensional array
arrayName is implicitly a pointer to the first element in the array
&arrayName is implicitly a pointer to the whole array
i.e.
arrayName returns address of the first element in the array i.e. &numbers[0] == numbers
&arrayName returns beginning address of the whole array

Getting a value of an array element:
We can get a value of an array element by its index.

Syntax:
arrayName[index]
Ex:
printf(“%d\n”,numbers[0]); // garbage integer value

Declaring and initializing one dimensional array:

Syntax:
data_type arrayName[size] = {list of values separated by comma};
Ex:
int numbers[5] = {0, 0, 0, 0, 0};

Setting new value to an array element:
We can set a new value to an array element using assignment operator.

Syntax:
arrayName[index]=newvalue;
Ex:
numbers[0]=10;
printf(“%d\n”,numbers[0]); // 10