C Arrays
C arrays is a collection of data items, with all of the same type and accessed using a common name. A one-dimensional(1-D) array is like a list; A two dimensional(2-D) array is like a table.
In C language there is no limits on the number of dimensions in an array, though specific implementations may.

Some texts refer to one-dimensional arrays as vectors, two-dimensional arrays as matrices, and use the general term arrays when the number of dimensions is unspecified or unimportant.
Always, Contiguous (adjacent) memory locations are used to store array elements in memory.
How to Declare Arrays in C?
- An Array variables are declared identically to variables of their data type like int, float etc., except that the variable name is followed by one pair of square [ ] brackets for each dimension of the array.
- Dimensions used when declaring c arrays must be constant expressions or positive integral constants.
- Uninitialized arrays must have the dimensions of their rows, columns, etc. listed within the square brackets.
Declaring a C arrays:
1 2 3 |
int a[10]; // integer array char b[10]; // character array i.e. string int tblArray[ 3 ][ 5 ]; //multi dimensional array |
Initializing Arrays
- An arrays may be initialized when they are declared, just as any other variables.
- Put the initialization data in curly {} braces following with the equals sign.
- An array may be partially initialized, by providing fewer data items than the size of the array. The remaining array elements will be automatically initialized to 0(zero).
- If an array is to be completely initialized, the dimension of the array is not required. The compiler will automatically allocate the size the array to fit the initialized data.
Initialization of an Array:
1 2 3 4 |
int A1[ 6 ] = { 1, 2, 3, 4, 5, 6 }; float sum = 0.0f, float A2[ 100 ] = { 1.0f, 5.0f, 20.0f }; double piFrac[ ] = { 3.141592654, 1.570796327, 0.785398163 }; |
Accessing an array elements:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include<stdio.h> int main() { int k; int a1[5] = {10,20,30,40,50}; // declaring and Initializing array in C //To initialize all array elements to 0, use int arr[5]={0}; /* Above array can be initialized as below also a1[0] = 10; a1[1] = 20; a1[2] = 30; a1[3] = 40; a1[4] = 50; */ for (i=0;i<5;i++) { // Accessing each variable printf("value of arr[%d] is %d \n", k, a1[i]); } } |
Output:
value of a1[0] is 10
value of a1[1] is 20
value of a1[2] is 30
value of a1[3] is 40
value of a1[4] is 50
For More Control Statements in C