An array in C is a fixed-size homogeneous collection of elements stored at a contiguous memory location. It is a derived data type in C that can store elements of different data types such as int, char, struct, etc. It is one of the most popular data types widely used by programmers to solve different problems not only in C but also in other languages.
The properties of the arrays depend on the programming language. In this article, we will study the different properties of Array in the C programming language.
- Fixed Size Collection
- Homogeneous Elements
- Indexing in Array
- Dimensions of Array
- Contiguous Storage
- Random Access
- Array name relation with pointer
- Bound Checking
- Array Decay
C Array Properties
1. Fixed Size of an Array
In C, the size of an array is fixed after its declaration. It should be known at the compile time and it cannot be modified later in the program. The below example demonstrates the fixed-size property of the array.
Example:
C
#include <stdio.h>
int main()
{
int array[5] = { 1, 2, 3, 4, 5 };
printf ( "Size of Array Before: %d\n" ,
sizeof (array) / sizeof ( int ));
array[6];
printf ( "Size of Array After: %d" ,
sizeof (array) / sizeof ( int ));
return 0;
}
|
Output
Size of Array Before: 5
Size of Array After: 5
2. Homogeneous Collection
An array in C cannot have elements of different data types. All the elements are of the same type.
Example:
C
#include <stdio.h>
int main()
{
int arr[3] = { 1, 2 };
arr[2] = "Geeks" ;
printf ( "Array[1]: %d\n" , arr[0]);
printf ( "Array[2]: %d\n" , arr[1]);
printf ( "Array[3]: %s" , arr[2]);
return 0;
}
|
Output
main.c: In function ‘main’:
main.c:12:16: warning: assignment to ‘int’ from ‘char *’ makes integer from pointer without a cast [-Wint-conversion]
12 | arr[2] = "Geeks";
| ^
main.c:17:28: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=]
17 | printf("Array[3]: %s", arr[2]);
| ~^ ~~~~~~
| | |
| char * int
| %d
Array[1]: 1
Array[2]: 2
3. Indexing in an Array
Indexing of elements in an Array in C starts with 0 instead of 1. It means that the index of the first element will be 0 and the last element will be (size – 1) where size is the size of the array.

Indexing of Elements in C Array
Example:
C
#include <stdio.h>
int main()
{
int arr[2] = { 10, 20 };
printf ( "Array[1]: %d\n" , arr[1]);
printf ( "Array[0]: %d" , arr[0]);
return 0;
}
|
Output
Array[1]: 20
Array[0]: 10
As we see in the above example, at index 1, the second element is present while at index 0, the first element is present.
4. Dimensions of the Array
An array in C can be a single dimensional like a 1-D array or multidimensional like a 2-D array, 3-D array, and so on. It can have any number of dimensions. The number of elements in a multidimensional array is the product of the size of all the dimensions.

Arrays of Different Dimensions
Example:
C
#include <stdio.h>
int main()
{
int arr2d[2][2] = { 1, 2, 3, 4 };
int arr3d[2][2][2] = { 1, 2, 3, 4, 5, 6, 7, 8 };
printf ( "2D Array: " );
for ( int i = 0; i < 2; i++) {
for ( int j = 0; j < 2; j++) {
printf ( "%d " , arr2d[i][j]);
}
}
printf ( "\n3D Array: " );
for ( int i = 0; i < 2; i++) {
for ( int j = 0; j < 2; j++) {
for ( int k = 0; k < 2; k++) {
printf ( "%d " , arr3d[i][j][k]);
}
}
}
return 0;
}
|
Output
2D Array: 1 2 3 4
3D Array: 1 2 3 4 5 6 7 8
5. Contiguous Storage
All the elements in an array are stored at contiguous or consecutive memory locations. We can easily imagine this concept in the case of a 1-D array but multidimensional arrays are also stored contiguously. It is possible by storing them in row-major or column-major order where the row after row or column after the column is stored in the memory. We can verify this property by using pointers.
Example:
C++
#include <stdio.h>
int main()
{
int arr[5] = { 1, 2, 3, 4, 5 };
int * ptr1 = &arr[1];
int * ptr2 = &arr[2];
printf ( "Address of arr[1] : %p\n" , ptr1);
printf ( "Address of arr[2] : %p" , ptr2);
return 0;
}
|
Output
Address of arr[1] : 0x7fffb8cc1ef4
Address of arr[2] : 0x7fffb8cc1ef8
In the above example, the difference between the addresses of arr[1] and arr[2] is 4 bytes which is the memory required to store a single integer. So, at memory addresses 0x7ffebc02e054 to 0x7ffebc02e057, arr[1] is stored and in the next 4 bytes, arr[2] is stored. The same is true for all the elements.
6. Random Access to the Elements
It is one of the defining properties of an Array in C. It means that we can randomly access any element in the array without touching any other element using its index. This property is the result of Contiguous Storage as a compiler deduces the address of the element at the given index by using the address of the first element and the index number.
Address of ith = Address of 1st Element + (Index * Size of Each Element)

Array in C
We can verify this by using Pointer Arithmetic.
Example:
C
#include <stdio.h>
int main()
{
int arr[5] = { 1, 2, 3, 4, 5 };
int * ptr = &arr[0];
printf ( "Array[3]: %d\n" , arr[3]);
printf ( "Array[3] using pointer to first element = %d" ,
*(ptr + 3));
return 0;
}
|
Output
Array[3]: 4
Array[3] using pointer to first element = 4
Note: We have not multiplied the size of each element in the code as the compiler deduce and multiply it automatically by itself whenever we perform pointer arithmetic.
7. Relationship between Array and Pointers
Arrays are closely related to pointers in the sense that we can do almost all the operations possible on an array using pointers. The array’s name itself is the pointer to its first element.
Example:
C
#include <stdio.h>
int main()
{
int arr[3] = { 1, 2, 3 };
int * ptr = &arr[0];
printf ( "Pointer to First Element: %p\n" , ptr);
printf ( "Arran Name: %p" , arr);
return 0;
}
|
Output
Pointer to First Element: 0x7ffec5059660
Arran Name: 0x7ffec5059660
The relationship between pointer and array is very deep and we can study more about it in other articles such as – Pointer to an Array | Array Pointer
8. Bound Checking
Bound checking is the process in which it is checked whether the referenced element is present within the declared range of the Array. In C language, array bound checking is not performed so we can refer to the elements outside the declared range of the array leading to unexpected errors.
Example:
C
#include <stdio.h>
int main()
{
int arr[3] = { 1, 2, 3 };
printf ( "Some Garbage Value: %d" , arr[5]);
return 0;
}
|
Output
Some Garbage Value: 0
As seen in the above example, there is no error shown by the compiler while accessing memory that is out of array bounds.
9. Array Decay
Array decay is the process in which an array in C loses its dimension in certain conditions and decays into pointers. After this, we cannot determine the size of the array using sizeof() operator. It happens when an array is passed as a pointer.
Example:
C
#include <stdio.h>
void func( int * arr)
{
printf ( "Sizeof Value in Function: %d" , sizeof (arr));
}
int main()
{
char arr[3];
printf ( "Sizeof Value in Main: %d\n" , sizeof (arr));
func(arr);
return 0;
}
|
Output
Sizeof Value in Main: 3
Sizeof Value in Function: 8
The size of the array in the main() is 3 bytes which is the actual size of the array but when we check the size of the array in func(), the size comes out to be 8 bytes which instead of being the size of the array, it is the size of the pointer to the first element of the array.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
23 Aug, 2023
Like Article
Save Article