In this tutorial, we will learn the C language Array syntax. First, let’s understand the definition of an array.
What is an array?
An array is a collection of elements of the same data type. It stores a collection/group of data values. All the elements of the arrays have the same data type and are stored in consecutive memory locations. An array in the C language has the following characteristics:
- Array Name
- Array Size
Type:- The data type of the elements stored in the array. All the elements stored in the array should have the same data type.
Name:- This indicates the name of the array.
Array Size:- This indicates the maximum number of elements that can be stored using the array.
C Array Syntax
Before using an array, it has to be declared in the C program. The declarative statement provides the following information to the C compiler.
- The data type of the elements in the array.
- The array name
- The array size
datatype array_name [array_size];
Here we have declared an array arr of integer type and its size is 10 which means, it can hold 10 integer values in the array.
Declaring multiple arrays syntax:
int a, float marks;
An array index is an integer value starting at 0. Thus if an array consists of n elements. The index can range from 0 to n-1